+ 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  );

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.