function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
udhayaganesh sridharanudhayaganesh sridharan 

I want to call visualforce email templates from apex class, is it possible?

Here is the requirement, there are 100's of visualforce email templates for each country.
I want to call visualforce email templates and pass few parameter from my apex class.
any suggestion is highly appreciated
Amit Chaudhary 8Amit Chaudhary 8
You can do like below
List<contact> lstcon=[Select id from contact limit 2];
 List<Id> lstids= new List<Id>();
 for(Contact c:lstcon)
 {
  lstids.add(c.id);
 }
 EmailTemplate et=[Select id from EmailTemplate where name = 'EmailTemplatename' limit 1]; // pass name here
 
 Messaging.MassEmailMessage mail = new Messaging.MassEmailMessage();
 mail.setTargetObjectIds(lstIds);
 mail.setSenderDisplayName('System Admin');
 mail.setTemplateId(et.id);
 Messaging.sendEmail(new Messaging.MassEmailMessage[] { mail });