Loading...
New Awarded Winner – IT & Development | 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

Related Articles

Sticky notes aren’t just for your desk anymore! In this tutorial, we’ll create a Lightning Web Component (LWC) in Salesforce that allows you to pin notes on your app page or record page. With a clean, interactive UI, these digital sticky notes ensure you never forget important tasks or details. What Will You Learn? By […]

Read More
How to Create Dynamic, Animated Charts in Salesforce LWC using Chart.js

Bring Salesforce data to life with dynamic charts inside Lightning pages! While Salesforce dashboards are powerful, sometimes business users want visual insights without leaving their current page. That’s where Chart.js with Lightning Web Components (LWC) becomes a game-changer. In this step-by-step guide, you’ll learn how to: Upload Chart.js as a static resource in Salesforce. Build […]

Read More
How to Encrypt and Decrypt Data in Salesforce Using Apex Crypto Class

Data security is more important than ever. Whether you’re storing customer information, sensitive business data, or private communication, ensuring that your data stays safe is critical. Salesforce provides built-in tools to help with this, and one of the most powerful yet easy-to-use approaches is encryption and decryption using the Apex Crypto class. In this blog, […]

Read More
Benefits & Step-by-Step Setup Guide for Salesforce Code Analyzer

When building on the Salesforce platform, code quality and security are non-negotiable, especially before submitting your app for a Salesforce Security Review. Catching bugs and vulnerabilities early not only saves time but also ensures compliance with Salesforce’s best practices. That’s where the Salesforce Code Analyzer comes in. This open-source tool scans your Apex classes, triggers, […]

Read More
A Step-by-Step Guide to Integrate Zoho CRM with Salesforce (Without Coding)

Managing data across multiple CRMs can be a real challenge for businesses that want a single source of truth. If your teams use Zoho CRM but want to move or sync all records seamlessly into Salesforce, you don’t need to write a single line of code. Thanks to MultiSync Made Easy, the integration process is […]

Read More
How to Integrate Salesforce with Copilot

Integrating Salesforce with Copilot is becoming an essential step for organizations aiming to streamline workflows, automate client data management, and unlock the power of AI-driven CRM. By connecting these two platforms, businesses can centralize customer information, reduce manual tasks, and accelerate growth. This guide walks you through the Salesforce–Copilot integration process with clear steps, Apex […]

Read More