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
Joe Andolina 7Joe Andolina 7 

MassEmailMessages and the TargetObjectIds and WhatIds values

Hey All,
My app is working sending lots of SingleEmailMessage from a loop. I was thinking it would be cool to use a MassEmailMessage instead. 

In the lists sent to setTargetObjectIds and setWhatIds, do they correspond to each other? If the lists are the same length, does the TargetObjectId need to map to the WhatId at the same index? 

Thanks
VinayVinay (Salesforce Developers) 
Hi Joe,

MassEmailMessage can send mails related to multiple records (WhatId and TargetObjectId). setTargetObjectIds method of MassEmailMessage can accept an Array of ID for contact, lead and user id's.

Check below references:
https://salesforce.stackexchange.com/questions/5169/whats-the-advantage-of-using-massemailmessage-instead-of-multiple-singleemailme
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_email_outbound_mass.htm
https://help.salesforce.com/articleView?id=email_mass_notes.htm&type=5

Limitations:
https://help.salesforce.com/articleView?id=limitations_email_mass.htm&type=5

Thanks,