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
SRILAKSHMI BSRILAKSHMI B 

System.LimitException: Too many Email Invocations: 11

Hi All,

 

I have  a Scheduler Apex class which will retreive all the contacts whose birthday is coming in next two days and send a mail to the contact owner with the list of contacts with upcomin birthdate.

 

 The body of the mail is dynamically calculated and put in the setHTML body of the singlemail message, I cannot use MassEmail Message as body of the each mail is not same.

 

This class will throw an exception if email message sent is more than 10 contact owners.

 

I cannot use MassEmail Message  with  same email template as body of the each mail is not same.

 

Can anyone please suggest what could be the work around for this iisue.

 

 

Thanks,

Srilakshmi B

Best Answer chosen by Admin (Salesforce Developers) 
Cory CowgillCory Cowgill

You can only invoke 10 Send Emails per Context. That is governor limit. You are hitting 11 emails and its bombing.

 

To fix this, you can create a Batch Apex Class that your Schedule Apex invokes. Move the Send Email logic inside your Batch Apex class and scope the batch so that is only processes 10 contacts at a time.

 

http://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#StartTopic=Content/apex_gov_limits.htm

All Answers

Cory CowgillCory Cowgill

You can only invoke 10 Send Emails per Context. That is governor limit. You are hitting 11 emails and its bombing.

 

To fix this, you can create a Batch Apex Class that your Schedule Apex invokes. Move the Send Email logic inside your Batch Apex class and scope the batch so that is only processes 10 contacts at a time.

 

http://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#StartTopic=Content/apex_gov_limits.htm

This was selected as the best answer
ca_peterson_oldca_peterson_old

More accurately the governor limit is calling the sendEmail method, and that method luckily takes a list of email messages to send.

 

If you put all of your SingleEmailMessages into a list and then call sendEmail on that list at the end of the job you can send much, much more than 10 emails (not sure of the limit, but it's at minimum 100).

batrulzbatrulz

Is this limit of "10 Send Emails" in Production or Sandbox ?