Send Email From Apex Using Email Template

In this blog post, we will go over sending a single email message with an email template.

But why use code when you can directly use Email templates by using Email Alerts? The answer is simple in email templates we can fetch limited/restricted data from a record. Like if we want to get some data of parent records we need to find some workaround but with apex, it is simply a SOQL away.

EmailUtilities.cli

Create this class and use it whenever you need to send an email from the apex.

[NOTE: If you want to add CC, and BCC lists you can do that in the same manner as I have added to emails]

How to use this class?

Step 1:

Create an email template(I generally use VF Templates it is easy to design) and use unique keywords you want to replace with record values.

Check this example screenshot I have highlighted the unique keywords in this template.

Step 2:

Call the class method

Summary
Article Name
Send Email From Apex Using Email Template
Description
Email templates are always the best option to send email because from them you can directly collect all the restricted/limited data; with apex it becomes much easier.
Author
Publisher Name
BugendaiTech Pvt Ltd
Publisher Logo
Spread the updates

Leave a reply