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
sindhu surusindhu suru 

MassEmailMessage using setTemplateId NEED URGENT HELP

When using setTemplateId with mass email, how to pass a record ID to the template to show all the merge fields. I have a mass email apex class and it does send the email but all the merge fields are blank. Please help.
Boris BachovskiBoris Bachovski
You need to specify "targetObjectId" for your email template, which is the contact, lead or user which the email goes to and also is used to merge the fields from. Also, if you have other objects that you need to merge fields from and the "targetObjectId" is a contact, then you can specify "whatId" to reference the other related object to merge fields from. Have a look at the documentation. (https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_email_outbound_single.htm#apex_Messaging_SingleEmailMessage_setTargetObjectId)