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
gautam_singhgautam_singh 

send email via different email templates to campaign members in apex

Hi, 

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.

Problem:

    Messaging.MassEmailMessage mail = new Messaging.MassEmailMessage();
    mail.setTargetObjectIds(LeadIds);
    mail.setTemplateId('00X30000001fOKk');
    Messaging.sendEmail(new Messaging.MassEmailMessage[] { mail });
    
    Messaging.MassEmailMessage mail = new Messaging.MassEmailMessage();
    mail.setTargetObjectIds(ContactIds);
    mail.setTemplateId('00X30000001fOKk');
    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.

Thanks
Gautam
Suneel#8Suneel#8
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
Hello,

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.

https://appexchange.salesforce.com/listingDetail?listingId=a0N30000005uxj5EAA (http://​https://appexchange.salesforce.com/listingDetail?listingId=a0N30000005uxj5EAA)

Do you want to know more details please click here https://goo.gl/e0RtSm

Regards
Venu E