0

I want to send auto emails to contacts with the related file. Each contact has its own file. I can't do this with the classic templates. Is there anyway to achieve this?

1
  • Can you describe more on what are you looking for?what have you tried so far? where did you get stuck? – sanket kumar Jan 17 at 6:37
1

With workflow, process builder, or flow email alert you won't be able to dynamically attach file.

If you are looking for the point and click option only you can check this out. This would install an unmanaged package and you can achieve it using point and click option. https://unofficialsf.com/flow-email-now-supports-attachments-and-organization-wide-email-addresses

https://unofficialsf.com/send-better-email-flow-action

https://unofficialsf.com/using-files-and-attachments-in-flow

If you are ok to write code, this can be achieved using apex. Here is an example:

Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
Messaging.EmailFileAttachment attach = new Messaging.EmailFileAttachment();

ContentDocumentLink cdl = [Select Id, ContentDocument.LatestPublishedVersion.VersionData from ContentDocumentLink where LinkedEntityId = 'RECORDID' AND ContentDocument.Title = 'FILE_NAME'];
Blob b = cdl.ContentDocument.LatestPublishedVersion.VersionData;
attach.setFileName('FILE_NAME.pdf');
attach.setBody(b);

email.setTemplateId(TEMPLATEID);//Replace TEMPLATEID with salesforce email template id
email.setTargetObjectId(TARGETOBJECTID);//Replace TARGETOBJECTID with user, contact or lead Id to which emai need to be sent.
email.setWhatId(RECORDID);//Record Id for which email template need to be applied

email.setFileAttachments(new Messaging.EmailFileAttachment[]{attach});

Messaging.sendEmail(new Messaging.SingleEmailMessage[]{email});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.