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
IndeevarIndeevar 

Handling Messaging.SingleEmailMessage apex governor limit of 10

HI

There is a requirement to send emails to contact owners for birthdays of their

respective contacts. So we are calling  Messaging.SingleEmailMessage method within an Apex class

in a loop. But in the Apex class there is a limitation that this method cannot be called more

than 10 times. Contact Owners are more than 50 though. The loop runs this many times .

How to handle this governor limit issue?
mikefmikef
in your loop you need to create 
Messaging.SingleEmailMessagemail objects, and put them in Messaging.SingleEmailMessagemail array.

Then put that array in the sendEmail method.
wilson34wilson34
hello mikef,

you've mentioned that you should put it in a loop and put the instantiated object,but how are we gonna put it in an array? sorry im a newbie to salesforce.

I would really appreciate it if you could give us a simple sample code on how to do this.


thank you very much