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
Naval Sharma4Naval Sharma4 

I am having issue in sending email from apex using an email template

My email template has some campaign member merge fields and when I am sending email it's not populating the cusotm field values.
 
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setTemplateId( et.Id);
mail.setTargetObjectId( cm.LeadId  );
//mail.setWhatId(cm.Id);
mail.setSaveAsActivity(false);

If I use CampaignId in the setWhatId() method, it doesn't populate the custom fields which are created on campaign member object. Also, I can't use the CampaignMember Id in the whatId.