You need to sign in to do that
Don't have an account?
How to attach Salesforce Files to Emails in an Apex Class?
I am using LEX and I want to have an Apex Class to include all the Salesforce Files that the Case has as attachments to the email and send the email.
I have a currently working Apex Class that sends the email just fine. I just need to add the attachment code and I am not sure where to start - I tried to use ContentDocumentLink but I have no clue of how to write that code. I doubt EmailFileAttachment works because I am using LEX which Salesforce Files work a bit differently.
Here is the current code:
// Mario E. // Sends Case information to the Interpreting Department // Email addresses are listed under Custom Labels: custom_VIEmailAddresses public class custom_VICasesForwarding { @InvocableMethod(Label='forwardToInterpretingDept') public static void forwardToInterpretingDept(List<ID> caseRecords){ Set<Id> createEmailAddresses = new Set<Id>(); List<Case> caseList = [select Id, Subject, CaseNumber, Case_Reason__c, Case_Issue__c, Description, Date_Time_of_Call__c, VINumber__c, Customer_s_VP__c, Outbound_Audio__c, Case_Thread_ID__c, (select Id from EmailMessages) from Case where Id IN :caseRecords]; for(Case c: caseList){ // Get Org Wide Email Address and then set it as Reply To address OrgWideEmailAddress[] owea = [select Id from OrgWideEmailAddress where Address = 'younameit@emailcompany.com']; // Define the email Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage(); if ( owea.size() > 0 ) { email.setOrgWideEmailAddressId(owea.get(0).Id); } // Sets the TO addresses String[] toaddr = new String[System.Label.custom_VIEmailAddresses.split(',')]; string[] ccaddr = new string[]{}; // Pulls field data from Case to include in the email body email.setSubject('FW: ' + c.CaseNumber + ' : ' + c.Case_Reason__c); email.setHtmlBody('Case Number: ' + c.CaseNumber + '<br/>' + 'Case Reason: ' + c.Case_Reason__c + '<br/>' + 'Case Issue: ' + c.Case_Issue__c + '<br/>' + + '<br/>' + 'Date/Time: ' + c.Date_Time_of_Call__c + '<br/>' + 'VI #: ' + c.VINumber__c + '<br/>' + 'Customer\'s VP #: ' + c.Customer_s_VP__c + '<br/>' + 'Outbound Audio #: ' + c.Outbound_Audio__c + '<br/>' + + '<br/>' + + '<br/>' + 'Case Description: ' + c.Description + '<br/>' + + '<br/>' + + '<br/>' + '<i>' + '*Note: If there are any null values, this means this information was not provided by the Case Owner prior to this submission.' + '</i>' + '<br/>' + + '<br/>' + + '<br/>' + '<span style="color: #cccccc;">' + c.Case_Thread_ID__c + '</span>' + '<br/>' + + '<br/>'); email.setToAddresses(toaddr); Messaging.sendEmail(new Messaging.SingleEmailMessage[] { email }); } Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage(); } }
Updated the code and am getting this error:
"Method does not exist or incorrect signature: void add(Messaging.EmailFileAttachment) from the type List<Id> (98:36)"
Please refer below code snippet to attach files:
Link: https://developer.salesforce.com/forums/?id=9060G0000005VtDQAU
Thanks,
Suraj
Suraj,
I am not sure how to modify that and make it fit in the rest of my code except for a few such as setFileName() and "WHERE LinkedEntityId =:" <--- those I can do.
Also, I do not see "setEntityAttachments()" anywhere...
And I am not sure how to set these as variables: "efa" and "fileAttachments"