0

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

1

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.

  • If this answer your issue, please mark it as accepted. – Saroj Bera May 31 '16 at 12:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.