We have a requirement to send email with attachment.
When a Opportunity stage is changed need to send a email to opportunity owner with attachments(Files added to that opportunity).
This work fine when attachments are added in salesforce classic and email will be sent to with attachments. But when we 'Upload File' in Notes And Attachment in partner community or lightning attachments are not added to the email. Because in partner community or in lightning attachments are added as ContentDocumnet.
Can any help us to add attach ContentDocument file in attachment.
Best Answer
If you have the
ContentDocument
Id you can fetch theContentVersion
file as this:Then you can linked them asEmailFileAttachment
:Edit: ofc you can mix both code, I just picked part of mine as example but do everything in one SOQL query
Edit²:
You can attach those
Messaging.EmailFileAttachment
withpublic Void setFileAttachments(EmailFileAttachment[] fileNames)
Or only the Ids with
public void setEntityAttachments(List<String> ids)