Loading...
New Winner – Cross-Border Excellence | Payoneer India 2026 Check out
Featured Recognized by Salesforce; Proven by impact! Check out

Sending an email from Apex Class is so easy.

The Apex Messaging.SingleEmailMessage class handles the email functionality available to Salesforce.

 

Basically there are two categories:

  • SingleEmailMessage – This class is used when a use case requirement to send to email to a single person. This contains methods for sending single email messages.
  • MassEmailMessage – This class is used when a use case requirement to send an email to a group.

Explanation about SingleEmailMessage :-

The following are methods for SingleEmailMessage.

  • setBccAddresses(bccAddresses) : This is Optional. This contains list of blind carbon copy (BCC) addresses. If the BCC compliance option is set in your org at the organization level, then the user cannot add any BCC addresses on standard messages. You will get the below error code: BCC_NOT_ALLOWED_IF_BCC_ COMPLIANCE_ENABLED. You can contact to your Salesforce representative for information on BCC compliance.
  • setCcAddresses(ccAddresses): This is Optional. This contains list of carbon copy (CC) addresses
  • setCharset(characterSet) : This is Optional . The character set for the email. If character set value is null, then the user’s default value is used.
  • setDocumentAttachments(documentIds) : This is Optional and Deprecated. Instead of this use setEntityAttachments() instead.
  • setEntityAttachments(ids) : This is Optional.
  • setFileAttachments(fileNames): This is Optional.
  • setHtmlBody(htmlBody) : This is Optional.
  • setInReplyTo(parentMessageIds) : This is Optional.
  • setOptOutPolicy(emailOptOutPolicy) : This is Optional.
  • setPlainTextBody(plainTextBody) : This is Optional.
  • setOrgWideEmailAddressId(emailAddressId) : This is Optional.
  • setReferences(references) : This is Optional.
  • setSubject(subject) : This is Optional.
  • setTargetObjectId(targetObjectId): This is required if using a template, if not then its optional.
  • setToAddresses(toAddresses) : This is Optional. The maximum number of email addresses allowed in setToAddresses method is 100.
  • setTreatBodiesAsTemplate(treatAsTemplate) : This is Optional. If this set to true, then the plain text, subject, and HTML text bodies of the email message are treated as template data.
  • setTreatTargetObjectAsRecipient(treatAsRecipient) : This is Optional.
  • setWhatId(whatId)

Email Limits :-

Inbound Email Limits

 

  • Email Services: Maximum Number of Email Messages Processed

(Includes limit for On-Demand Email-to-Case) :- Number of user licenses multiplied by 1,000; maximum 1,000,000

  • Email Services: Maximum Size of Email Message (Body and Attachments) :- 10 MB
  • On-Demand Email-to-Case: Maximum Email Attachment Size :- 25 MB
  • On-Demand Email-to-Case: Maximum Number of Email Messages Processed

(Counts toward limit for Email Services):- Number of user licenses multiplied by 1,000; maximum 1,000,000

Mainly there would be two types of error while sending email from Apex as explained below:-

 

  • Transaction based errors:- We can send 100 emails per SingleEmailMessage

Per day (24 hour) email limit:- We can send 1000 emails per day

Amazon translation API :-

An affordable service for more natural, precise translations. It rests on state-of-the-art deep learning models, as opposed to traditional statistical and rule-based algorithms.

In our implementation, a VisualForce Page comes up with a Lightning Component to accept a source and target language, subject, recipient email, and body. Only the message body gets translated. It goes without saying, that the functionality builds on the standard ‘Messaging.SingleEmailessage’ to send out emails to individuals. Here’s a look at our source code for you to dive in:

Here is the Amazon API authentication code:-

Here we are explaining SingleEmailMessage category. Below is the code snippet which sends an email to single user from apex. I have created one Lightning component and controller related to it. Lightning component have Send Email button.

Once user clicks on the button, we are sending email using apex code.

Try this for sending emails to a single user.

Step 1 :

Step 2: Create a lightning component and paste the code below.

Lightning Component:

JS controller:

JS Helper:

Lightning App:

VisualForce Page: This is used to display the lightning component.

Step 3:

You can click on Preview button which is on Visualforce page

OR

 

You can Go to the URL and type (Change the yoursalesforceinstance with your salesforce org URL)

 

https://yoursalesforceinstance.com/apex/VfPageName

Conclusion

The above integration lets you compose, preview and send out translated emails to individuals and mailing lists. We hope this nudges you to send out translated emails for client engagement efforts of your own. For further assistance in setting up similar integrations and marketing enablements, do reach out to us at sales@hicglobalsolutions.com.

Find out more here
How to Send Emails using Templates with Lightning Component in Salesforce

No Data Found.

Related Articles
From SMBs to Enterprises: Why Salesforce CRM Remains the Choice for Every Business Size

Running a modern business requires a robust Salesforce CRM platform that connects teams, organizes customer data, and delivers real-time operational insights. In today’s competitive environment, waiting for information across disconnected systems is no longer practical, especially when modern buyers expect immediate responses across every channel. For years, the software was primarily associated with large corporate […]

Read More
How to Integrate NikoHealth to Salesforce

Healthcare organizations using NikoHealth often need patient, insurance, order, invoice, and prescription data available inside Salesforce. As data grows, manually updating records across systems becomes difficult and can lead to delays, duplicate work, and data inconsistencies. NikoHealth to Salesforce integration helps solve this challenge by automatically synchronizing data between both platforms. Instead of building custom […]

Read More
Flow Orchestrator vs. Traditional Flows: When to Use Each for Salesforce Automation

Businesses use Salesforce automation to reduce manual work, improve efficiency, and automate repetitive business processes. Two commonly used automation approaches inside Salesforce are Traditional Flows and Flow Orchestrator. Traditional Flows are mainly used for simple automation tasks such as updating records, sending notifications, creating tasks, and automating business logic. Flow Orchestrator is designed for more […]

Read More
The Rise of Agentic Government: How AI Agents Are Transforming Public Services

Government technology has often been seen as slower to evolve than the private sector. But Salesforce’s latest research challenges that idea in a big way. In fact, the new findings suggest that public sector organizations may now be moving faster than many businesses when it comes to adopting AI agents and preparing for a more […]

Read More
How To Use Email Service in APEX

Managing approvals, updates, and record changes directly from email can significantly improve efficiency within Salesforce workflows. Instead of logging in, navigating records, and manually updating fields, users can simply respond to emails and trigger automated updates using Email Service in APEX. This approach is especially useful for businesses leveraging Salesforce automation and looking to enhance […]

Read More
Design and Implementation of Salesforce-Jira Task Integration

Businesses have been using Salesforce for CRM operations and Jira for Agile project tracking. However, without integration, teams manually update both systems, leading to data inconsistency and inefficiency.This mechanism establishes a real-time integration between Salesforce and Jira, allowing seamless synchronization of tasks and agile board statuses.  A custom Salesforce dashboard was developed that replicates Jira-style […]

Read More
Our Location worldwide
Indian Flag India
7th Floor, A-10, Pegasus Tower, Sector 68, Noida, Uttar Pradesh 201301 +91-1203669505
United States of America Flag USA
333 West Brown Deer Road Unit G – 366 Milwaukee WI, USA 53217 +1(262) 310-7818
United Kingdom Flag UK
7 Bell Yard, London, WC2A 2JR +44 20 3239 9428
CA Flag Canada
HIC Global Solutions INC
6D - 7398 Yonge St #1124 Thornhill, ON L4J 8J2 Canada +1(262) 310-7818