-
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
What is Salesforce Web3 Tech and How Does it help in Creating Reliable, Long-Lasting Communities
With a unified platform and the help of Salesforce Web3, organizations can efficiently scale while creating linked consumer experiences across Web2 and Web3. Web3, referred…
Top Features and Updates from Salesforce Winter’25 Release
Get ready to embrace the excitement of the Salesforce Winter '25 Release! This season's update is like the first snowfall, bringing a flurry of innovative…
Unleash the True Potential of Salesforce with Professional Administration Services
There are fair chances that you are sold out on the expansive range of features and benefits that Salesforce offers. However, the issue arises when…
Popular Salesforce Videos
How To Create a Dashboard in Salesforce CRM Analytics (Tableau CRM) From Scratch | Part 1 - Dataset
Salesforce CRM Analytics (formerly Tableau CRM) is a powerful tool for data analysis and visualization. The foundation of any CRM Analytics dashboard is a dataset.…
Creating a Rollup Using DLRS | Salesforce Tutorial
In certain situations, an object does not support a roll-up, or the relationship is not permitted. Learn how to make it possible by using the…
Salesforce on Salesforce: How Salesforce Uses Trailhead to Drive Enablement
With Trailhead, Salesforce is transforming the learning experience for our employees at every step of their career journey. Join us to learn tips, tricks and…