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.
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?
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.
Call the class method