22

What does the exception mean? It does not seem to be related to the Number of email invocations limit because of the following line at the end of the log: Number of Email Invocations: 5 out of 10

I also check the email limits before sending an email:

Integer used = Limits.getEmailInvocations();
Integer emailLimit = Limits.getLimitEmailInvocations();
if(used >= emailLimit){
    //print email text instead of email it.

}
else{
    //send email
}

Any clarification on this exception would be much appreciated. Thanks!

3
  • Are you working in a developer edition org? i believe these have lower daily limits (around 10 emails per day). Commented Jan 27, 2014 at 21:58
  • The Limits Static Methods are per transaction limits, and do not divulge per organization limits. For example, getLimitFutureCalls tells you nothing of the organization's daily future call limit (250k or licenses * 200, whichever is greater). Instead, you will know how many more future calls you can execute before your transaction fails.
    – sfdcfox
    Commented Jan 27, 2014 at 22:08
  • I am working in a developer edition org. Commented Jan 28, 2014 at 15:10

5 Answers 5

20

Per the Governor Limits, you can only send 5000 single emails a day (or less, depending on license).

Using the API or Apex, you can send single emails to a maximum of 5,000 external email addresses per day based on Greenwich Mean Time (GMT). Single emails sent using the Salesforce application don't count toward this limit. There’s no limit on sending individual emails to contacts, leads, person accounts, and users in your organization directly from account, contact, lead, opportunity, case, campaign, or custom object pages.

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_gov_limits.htm

4
  • 5
    As a side note, you can gracefully catch the error with Messaging.reserveMassEmailCapacity and Messaging.reserveSingleEmailCapacity, which lets you catch exceptions when your organization would be exceeded. You can either back off the number sent, or inform the user that there are insufficient messages remaining.
    – sfdcfox
    Commented Jan 27, 2014 at 22:04
  • Looks like I will have to wait until tomorrow and see if that is the issue. (I have a sneaking suspicion that it is.) In the mean time, I will add that exception handling. Commented Jan 27, 2014 at 22:11
  • Email is working now. Looks like I hit a daily org limit. Commented Jan 28, 2014 at 15:17
  • Messaging.reserveSingleEMailCapacity() didn't seem to work. It was not throwing an exception when I called it. Commented Jan 28, 2014 at 15:18
12

Here is my attempt to combine all of the answers given, and to interpret the SF Documentation provided on email limits.

A SINGLE_EMAIL_LIMIT_EXCEEDED exception is thrown when the daily Messaging.SingleEmailMessage limit is exceeded. This exception can be thrown in other cases as well, like when email deliverability is not set correctly.

Each SingleEmailMessage sent counts toward the limit, even if it is sent to the same email address.

A Dev Edition org has a single email limit of 15 messages. (assuming 1 recipient per email)

The single email limits don't take unique addresses into account. For example, if you have [email protected] in your email 10 times, that counts as 10 against the limit.

In Developer Edition organizations and organizations evaluating Salesforce during a trial period, your organization can send single emails to a maximum of 15 email addresses per day.

A non Dev org has a single email limit of 1000 messages. (assuming 1 recipient per email)

Using the API or Apex, you can send single emails to a maximum of 1,000 external email addresses per day based on Greenwich Mean Time (GMT).

4

I had this error a couple weeks ago. For me, it has something to do with the Sandbox not being configured to deliver email.

My resolution was to go into Admin Setup > Email Administration > Deliverability

There is a setting called 'Access to Send Email', I moved that to 'All email' and it worked. https://help.salesforce.com/apex/HTViewHelpDoc?id=emailadmin_deliverability.htm&language=nl

4

When working in Developer Edition orgs you are subject to lower email limits.

In Developer Edition organizations and organizations evaluating Salesforce during a trial period, your organization can send mass email to no more than 10 external email addresses per day. This lower limit does not apply if your organization was created before the Winter '12 release and already had mass email enabled with a higher limit. Additionally, your organization can send single emails to a maximum of 15 email addresses per day.

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

While working in an org like this you could possibly work around this by keeping the Messaging.SendEmail() function commented out until final testing otherwise whilst running Apex tests you can very quickly exceed this limit.

3
  • 3
    Unit Tests don't actually send the email and don't actually count against your daily limits.
    – sfdcfox
    Commented Jan 28, 2014 at 15:59
  • Ah okay thanks for clearing that up. I've run into issues however when running tests after hitting the email limit via manual testing, this then stops the tests as they hit this Single limit exceeded issue, it was just something i thought to mention as working in a dev org this limit of 10 emails is very easy to exceed. Commented Jan 28, 2014 at 16:33
  • That, though, is true. The moral of the story is that you should prefer unit testing over manual testing whenever possible, although when you are manually testing, I would definitely agree that you should be commenting out any sendEmail functions unless you're specifically testing deliverability/how the email looks.
    – sfdcfox
    Commented Jan 28, 2014 at 16:42
3

In addition to using Messaging.reserveSingleEmailCapacity(1); and handling the resulting exceptions to detect the imminent SINGLE_EMAIL_LIMIT_EXCEEDED exception I've found it useful to check the OrgLimits. E.g.

Map<String,System.OrgLimit> limitsMap = OrgLimits.getMap();
System.OrgLimit apiRequestsLimit = limitsMap.get('SingleEmail');
System.debug('Limit Name: ' + apiRequestsLimit.getName());
System.debug('Usage Value: ' + apiRequestsLimit.getValue());
System.debug('Maximum Limit: ' + apiRequestsLimit.getLimit());

If the getValue() plus the number of additional emails you will send exceeds the getLimit() value then the org limit will be hit.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .