-
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
Boost productivity with the Salesforce Inspector Chrome Extension
With digitization, the workload in every organization is growing exponentially, creating a lot of mundane, but essential tasks. These activities are time-consuming and not so…
10 Key Benefits of Salesforce Field Service for Your Company
For many companies, the border between an excellent or poor customer experience is based on the quality of the field services they offer. Satisfied consumers…
Get Selected Records from ListView in Visualforce Page | GETRECORDIDS JavaScript | StandardSetController Salesforce
In this article, you will learn to use GETRECORDIDS function to get selected records IDs in Visualforce page. Requirement - Convert onclick JavaScript on custom…
Popular Salesforce Videos
Salesforce for Manufacturing: How to Digitize Your Sales Processes
As a manufacturing sales leader, you’re looking for ways to go digital with your sales processes and improve channel performance. In this video, you’ll learn…
What is Classic Email Templates and Documents? Salesforce Tutorial
Classic Email Templates are also called Communication Templates. Watch this video and learn all about it, if you have any doubts or concerns, do reach…
Pros & Cons of Lightning Component vs. 3rd party frameworks in Salesforce UI development
Nikita drops by to share his invaluable experience of using popular 3rd party frameworks in Salesforce. http://media.blubrry.com/salesforceway/audio.xmcdn.com/group42/M05/25/57/wKgJ81rXk6XjaZIAAU_I_KtprFM998.m4a