-
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
Syna World Windbreaker: Where Streetwear Style Meets Everyday Performance
In modern fashion, outerwear has evolved beyond basic protection. Today, jackets and windbreakers represent personality, confidence, and lifestyle. The Syna World Windbreaker is a perfect…
Salesforce Field Service Lightning Functional Data Model
Today, we will be discussing the data model of Field Service Lightning. This article will be slightly technical, so buckle up your seat belt hoses.…
How to Use the Salesforce Marketing Cloud for Business Growth in 2024?
Salesforce Marketing Cloud is a leading email marketing software for creating and managing successful marketing campaigns and nurturing customer relationships. This SaaS platform allows marketers to use email personalization to…
Popular Salesforce Videos
Salesforce Lightning Design System (SLDS) and Components
The Salesforce Lightning Design System (SLDS) helps you build applications with the look and feel of Lightning Experience without writing a single line of CSS.…
Salesforce Admin Interview Questions And Answers For Freshers & Experienced
This Salesforce Admin Interview Questions and Answers video includes all the frequently asked Interview questions that give you an idea to crack your Salesforce Admin…
Replicate Salesforce Data in Real-Time with Change Data Capture
In this video, we will see how to replicate Salesforce data Migrate your batch processing, scheduled ETL, and nightly workloads to event-driven, real-time integrations using…