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
AvinAvin 

Too many email invocation: 11

Hi,

 

I have written a batch class. In SingleEmailMessage, I have defined the To address and list of CC address.

CC address is equal to the number of contacts present in Account.

 

In schedule class, Batch Size of 1 is defined.

But I am getting the Error: Too many Emal invocation 11.

 

Please help me get the solution of this problem

 

Thanks,

Bhawani SharmaBhawani Sharma
Looks are you are sending emails in loop. Limit on sending email per transaction using Apex is 10.
Puja_mfsiPuja_mfsi

HI,

Do not call sendEmail()  method inside for loop,You need to create a list of "SingleEmailMessage" and add the SingleEmailMessage instance to that particular list.Then outside the for loop call sendEmail() method with that list.

As:

 

List<Messaging.SingleEmailMessage> mails  = new List<Messaging.SingleEmailMessage>();

for( Contact con : conList ) {

          Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();

         /**** Add to,cc,body,subject etc. in message.****/

         mails.add(message);

}

Messaging.sendEmail(mails);