Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

I am working on sending mails to 50 clients at one go( basically at lead genration). I was able to send 11 mails until I used static body through SetHtmlBody() of my Batch class having Database methods. But the problem arises when I have to choose the template dynamically as we have a form having radio buttons. Now the same error is coming: Too many email invocations : 11.

Please help me to sort this error.

share|improve this question
1  
Can you show the source code with your invocation? Messaging.sendEmailMessage takes a list. It's usually possible to assemble multiple emails, but send them all in one invocation. –  user320 Jan 18 '13 at 13:09
add comment

2 Answers 2

As per the documentation re governor limits, you can only actually call the sendEmail method of the Messaging class 10 times.

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_gov_limits.htm

You are receiving this message because you will have called it 11 times in the same context. Depending on your use case, there are a couple of ways to circumnavigate this. If you really do need to call the sendEmail method more than 10 times, you could use a Batch Apex class and set your batch size to 1 (to 10 depending how you implement it). This would allow you to call the method 10 times per execute iteration. See this blog entry for details:

http://forceguru.blogspot.co.uk/2011/03/how-to-send-more-than-10-e-mails.html

Its not clear from your post whether that is what you want to do, but you can also send the same email to multiple addresses using the following format:

setToAddresses( new String[] {address1, address2, address3} )

Or, different emails to different addresses using something like:

List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>();
// add mails to list here
Messaging.sendEmail( mails );

See the documentation here:

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_email_outbound.htm

share|improve this answer
add comment

I have an answer on how to do this already on a similar question: http://salesforce.stackexchange.com/a/3999/60

In summary, Messaging.sendEmail accepts a List, which means each call to it can include a large number of emails to send - you need to bulkify your send email calls just like you would in an apex trigger.

share|improve this answer
    
lol, I was on holiday when you did that one, that's my excuse and i'm sticking to it ;) –  Phil Hawthorn Jan 18 '13 at 19:53
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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