-
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

How Salesforce Partner Portal Help Strengthen Partnerships?
Businesses in every niche and industry are worried about one of the most critical aspects—strengthening partner connections. But why? By building better connections, businesses can…

Learn All About the Lightning Web Components in Salesforce
Why Lightning Web Components (LWC)? As of now, the AURA framework which was used for Lightning Components is outdated and it was time for a…

Lead Assignment to the User in a Round Robin fashion | Salesforce Tutorial
Balance your team's workload by automatically assigning new leads to each user. A round-robin assignment means that all new leads will be assigned the same…
Popular Salesforce Videos
Easy Salesforce Lightning Experience Tricks for Admins
Learn how to enhance the screens for your end users by leveraging Related List - Quick Links, Report Charts and dynamic filters to show the…
Business Days in Salesforce CRM Analytics (Tableau CRM)
It's common for businesses to want to take business days into account when showing data on a dashboard in CRM Analytics (formerly Tableau CRM) to…
5 Strategies to Get a Salesforce Job with No Experience
If you have questions like how to jump start your Salesforce career as a freshers? Or what should be your approach to start Salesforce career?…