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

send email via different email templates to campaign members in apex


In Campaign Object, I have 1 Field - Email template. In a Batch, I am processing a list of campaignMembers(from different Campaigns)
to send them an email with specified template. I am using  Messaging.MassEmailMessage and hence froth no Loop for Emails.


    Messaging.MassEmailMessage mail = new Messaging.MassEmailMessage();
    Messaging.sendEmail(new Messaging.MassEmailMessage[] { mail });
    Messaging.MassEmailMessage mail = new Messaging.MassEmailMessage();
    Messaging.sendEmail(new Messaging.MassEmailMessage[] { mail });
This is currently taking Hard-Coded value.What I need is it for every campaignMembers record it should check the campaign's Email Template Field & sends the email using that specified Email Template. Loop does not works ! :-( 

Any help/approach would be highly appreciated.

As all the campaign memebers are not from Single Campaign, use Messaging.SingleEmailMessage class to send emails to members individually with a loop.Else you can group campaign members of same campaign and use Messaging.MassEmailMessage to send mass emails
Venu EVenu E

With Salesforce campaign, you don’t have to be an HTML expert to create stunning, professional emails – in fact, you don’t need to know how to code at all. our MassMailer campaign is simple to use and has a Salesforce-friendly interface that you will feel comfortable using right out of the gate. Create your emails, send them immediately, or schedule them to launch at a later date and time. With MassMailer, you have the power.

Say Hello to MassMailer and Say Goodbye to Salesforce Limitations. (http://​

Do you want to know more details please click here

Venu E