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
lovetolearnlovetolearn 

toAddresses for MassEmailMessage class

Hi, 

 

I see that there is not setToAddressses method for the MassEmailMessage class like there is for SingleEmailMessage. Is there then any way to specify the recipicent's email address for mass emails?

 

Thanks in advance.

kiranmutturukiranmutturu

This is why it is different from singleemail message. Why can't you make you of ID's of the respective object to send an email using MassEmail.  

lovetolearnlovetolearn

I tried that, but I was unable to specify the recipient's email address. 

kiranmutturukiranmutturu

its not required to explicity specify the email address when you are using the mass email...the object id itself is enough to pick up the email field of the respective user like below

 

  Messaging.MassEmailMessage mail = new Messaging.MassEmailMessage();
            mail.saveAsActivity = false;
   
            mail.setTargetObjectIds(mailToIds);///Here mailToids are contact ids in my scenario....
            mail.setTemplateId(e.Id);
           
            mail.setUseSignature(false);
            mail.setSaveAsActivity(false);


            // Send the email
            Messaging.sendEmail(new Messaging.MassEmailMessage[] { mail });