-
I am new to salesforce. i want to send email with attachment
I am new to salesforce. i want to send email with attachment that stored in static resources. please tell me how to do it
Answer-
public class EmailStaticResource {
public void StaticresourceDataAsEmail(){
Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
email.setUseSignature(false);
email.setSaveAsActivity(true);
email.setSubject('Send Email using staticResource as body of mail ');
String[] toAddresses = new String[] {'[email protected]'};
email.setToAddresses(toAddresses);
email.setHtmlBody('<html><body>Dear devoplers<b>See the code for Email service</b></body></html>');
StaticResourcesr = [Select Name, Id, Body From StaticResource where Name = 'Document'];
Blob tempBlob = sr.Body;
Messaging.EmailFileAttachmentefa = new Messaging.EmailFileAttachment();
efa.setBody(tempBlob);
efa.setFileName('attachment.pdf');
email.setFileAttachments(new Messaging.EmailFileAttachment[] {efa});
Messaging.SingleEmailMessage[] emailList = new Messaging.SingleEmailMessage[] {email};
Messaging.sendEmail(emailList);
}
}
Log In to reply.
Popular Salesforce Blogs
Data Management in Salesforce - Here is All You Need to Know
This is the important part to understand clearly as an administrator. In this blog we are going to learn about how the data is imported…
How to Install HubSpot and Salesforce Integration?
Salesforce is a San Francisco, California (USA) based CRM company that brings companies and customers together on a highly secured cloud platform. It has one…
Maximize Your Salesforce Investment With Our Custom Solutions
For any business, small or big, providing great customer service determines its success. Salesforce is a full-fledged ecosystem that enables you to connect with your…
Popular Salesforce Videos
Salesforce Administrator and Developer Training | Salesforce Training Videos
This Salesforce Training video is a demo of how the live online instructor-led classes take place after you enroll for the Online Classroom. All training…
Find Newly Created Fields in Salesforce
In this series, we do a deep dive into a specific business problem and share how one #AwesomeAdmin chose to solve it. Once you learn…
Heroku | Salesforce Development Course
Knowledge of Heroku is also required to crack the Salesforce PD 1 Certification Examination. Let’s understand what Heroku is and what are its uses, in…