i have a 100 contacts i want to send a email to all 100 contacts which user selected.in this case which email(single or mass) i need to choose.if choose single email message i can only send 10 emails only. so i chosen mass email but my TL told me to use Single email only,i am confusing which one i need to implement.why i should use single only..?why not mass..? any problem with mass email...? messaging.singleemailmessage or messaging.massemailmessage
-
10 email ahh really? no you can send all the 100 contacts at a time.. limit related to 10 is you can only invoke single email message send method only 10 times in single transaction.. check this discussion What's the Advantage of using MassEmailMessage instead of multiple SingleEmailMessage?– Ratan PaulMay 31, 2016 at 11:46
Add a comment
|
1 Answer
You can only call sendEmail 10 times within the same context. you can build up an array of singleemailmessage and then send them all in one call. This will avoid the 10 limit per call.
List<Messaging.SingleEmailMessage> allMails = new List<Messaging.SingleEmailMessage>();
//now do your loop
.... {
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setToAddresses(emailsLeads);
// mail.setCcAddresses(ccAddresses);
String subject='GoToMeeting Invitation Details for '+subject;
String body='test';
mail.setHtmlBody(body);
mail.setSubject(subject);
allMails.add(mail);
....
}
//Finished your loop? Now you have an array of mails to send.
//This uses 1 of your 10 calls to sendEmail that you are allowed
Messaging.sendEmail(allMails);
You can read more from this link.