-
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[] {'ganesh.maharana@janbask.com'};
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

Best Practices of Apex In Salesforce - Here's the Complete Guide
Please follow these Salesforce Best Practices to improve our code Quality, Readability, and Reusability. Also, you can use Salesforce Best Practices to optimize our code.…

Salesforce Automation — Business Cases
In this series of articles about Salesforce Automation, we have explained and demonstrated how each of the automation tools can be used and provided an…

What are Record-triggered Flows in Salesforce? | The Ultimate Guide
One of Salesforce's most potent features is Record-Triggered Flows (RTFs). You may automate procedures and lessen human labor by using RTFs to design flows that…
Popular Salesforce Videos
Develop a Basic Slack App For Salesforce
Build Slack Apps integrated with Salesforce. Use Heroku to host Slack apps built using Slack Bolt Framework and get connected to Salesforce using Node.js library…
Running a New Report in Salesforce
After logging into Salesforce, Go to the reporting section by clicking on the Reports tab at the top of the page, Click on the New…
Salesforce Admin Mock Interview Questions and Answers
In this Salesforce Mock Interview Series, I'm dropping the seventh podcast/video of the Salesforce Admin Mock Interview Questions and Answers. This will help you to…