-
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 Mapping and Merge Mapping in Salesforce - Everything you Need to Know
Adobe Sign is the high rated eSign tool which is provided by Salesforce AppExchange for the Adobe Document Cloud eSign facilities. It has tightly integrated…
5 Ways to Grow and Build Trust in Finance Business | Salesforce
We all know of the financial crisis in 2007. The one that sent shockwaves in the financial business, not only in the US but all…
5 Reasons For Students To Become A Salesforce Developer
Salesforce CRM technologies have been an integral part of the world for quite a while now with more and more people coming to work in…
Popular Salesforce Videos
How to setup Visual Studio Code for Salesforce ? | Link VSCode with Non Scratch Org using SFDX CLI
Hello Trailblazers, In this video, we're going to learn how we can setup vscode for Salesforce development. I am going to tell you how you…
Success from Anywhere with Salesforce EMEA Leaders
Watch this video to learn about Success from Anywhere with Salesforce EMEA Leaders. Do let us know your opinions in the comment section.
Salesforce and Slack | Meet the Slack-First Customer 360
Salesforce and Slack have joined forces to create the Slack-First Customer 360. Now it’s easier than ever to connect customers, employees, and partners with the…