How can be avoided error SINGLE_EMAIL_LIMIT_EXCEEDED Email limit exceeded if need to send email to one single user?

I have been looking for some time looking for a way how can error SINGLE_EMAIL_LIMIT_EXCEEDED Email limit exceeded be avoided if I need to send one simple email to one single user, for example, myself.

15 Email invocations limit on Developer Edition is a very small number, and it is usually quickly exceeded. Using Workflow Email Alerts may help to send more emails but still it is limited.

Looks like I have found an answer very long time back but didn’t write it down at that time and forgot it. So today I started investigating this again and decided to store the solution found somewhere.

It is interesting that this documentation has a small sentence answering this question. https://help.salesforce.com/apex/HTViewSolution?id=000002490&language=en_US

Emails sent using setTargetObjectId() set against the user object do not count against the SingleEmailMessage limit.

It is very interesting that if I run this code

Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setToAddresses( new List<String>{'julfy@i.ua'} );
mail.setSubject( 'test 2' );
mail.setHtmlBody( 'test 2' );
Messaging.sendEmail( new Messaging.SingleEmailMessage[] { mail } );

it fails with error

Line: 14, Column: 1 System.EmailException: SendEmail failed. First exception on row 0; first error: SINGLE_EMAIL_LIMIT_EXCEEDED, Email limit exceeded: [] while if I execute the code

Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setTargetObjectId( UserInfo.getUserId() );
mail.setSaveAsActivity( false );
mail.setSubject( 'test 2' );
mail.setHtmlBody( 'test 2' );
Messaging.sendEmail( new Messaging.SingleEmailMessage[] { mail } );

I see no errors.

Looks like someone else also has mentioned this here: http://salesforce.stackexchange.com/a/17143/3716

However, that answer is undervoted and doesn’t appear on the top on googling.

Advertisements
This entry was posted in apex, email, example, Free, limits, mail, mass, Posts in English, salesforce and tagged , , , , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s