You need to sign in to do that
Don't have an account?

Apex - Attaching files to an Email
I am working on sending an email with the opportunity files based on certain criteria. I am able to send an email with the 'versionData' as an email body which is queried from 'Contentversion'.
Problem: When i try to open the attachment from email it says 'Preview not available' and also i am not able to open the downloaded attachment too.
Please find the code below and let me know where I am going wrong. Thanks!
Problem: When i try to open the attachment from email it says 'Preview not available' and also i am not able to open the downloaded attachment too.
Please find the code below and let me know where I am going wrong. Thanks!
List<id> ContentDocumentids = new List<id>(); for(contentDocumentLink CDLink : [SELECT LinkedEntityid, ContentDocumentid FROM contentDocumentLink WHERE LinkedEntityid=:'Object id']) { ContentDocumentids.add(CDLink.ContentDocumentid); } for ( ContentVersion cversion : [SELECT title, PathOnClient, versiondata FROM contentversion WHERE ContentDocumentId IN :ContentDocumentids AND title LIKE 'WOCF%']) { blob WOCFbody = cversion.versiondata; system.debug('body : '+WOCFbody+'-----------'+cversion.title); Messaging.Emailfileattachment efa1 = new Messaging.Emailfileattachment(); efa.setFileName(war2.opportunity__r.name+'-'+cversion.title); efa.setBody(WOCFbody); fileAttachments.add(efa); }
All Answers
ContentType for EmailFileAttachment uses the same ContentType values as Attachment. for pdf, use 'application/pdf'.
Here is a full list I found: https://salesforce.stackexchange.com/questions/102542/valid-values-for-contenttype
Can any one explain me how to add this file to a classic email template. Where should we add it. What is the process.
Thanks in Advance