16

my email limit is exceeded after sending 10-12 emails..what could be the problem..as i have seen the limit is 1000 emails/day.i am not able to find out what could be the problem..Can some give me some suggestions. As i also know we can send 10 emails in a single transaction.I am sending emails in a batch class.

I am calling this batch class on button click and filling emailList with emailsId's.

                    String query='Select id from Lead';//No use of this query
                    Batch_send_emails bse=new Batch_send_emails();
                    bse.query=query;                                    
                    bse.resendEmails=emailList;
                    database.executebatch(bse);


        **Batch Class**

         if(!resendEmails.isEmpty())
          {
              for(String s:resendEmails)
               {
                  emailsLeads.add(s);
               }
          }


        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        mail.setToAddresses(emailsLeads);
       // mail.setCcAddresses(ccAddresses);
        String subject='GoToMeeting Invitation Details for '+subject;
        String body='test'; 
        mail.setHtmlBody(body); 
        mail.setSubject(subject);
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail }); 
        }  
2
  • How many email addresses are there in your emails? The limit is 1,000 email addresses per day, not 1,000 emails.
    – Kevin Lam
    Commented Jan 20, 2014 at 23:12
  • Update : Limit upgraded to 5K. Ref. help.salesforce.com/…
    – Ysr Shk
    Commented Apr 29, 2017 at 9:01

7 Answers 7

24

There is a limit on the number of emails you can send from Apex, this is 5,000 per 24 hours and you would need to raise a case and engage with Salesforce to get this raised.

I think that the error message you are seeing there refers to a different limit, which is that you can only call sendEmail 10 times within the same context. Is it possible that your apex code is calling that in a loop?

You should do something like this

List<Messaging.SingleEmailMessage> allMails = new List<Messaging.SingleEmailMessage>();
//now do your loop
    .... {

        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        mail.setToAddresses(emailsLeads);
       // mail.setCcAddresses(ccAddresses);
        String subject='GoToMeeting Invitation Details for '+subject;
        String body='test'; 
        mail.setHtmlBody(body); 
        mail.setSubject(subject);
        allMails.add(mail);
 ....
 }
//Finished your loop? Now you have an array of mails to send.
//This uses 1 of your 10 calls to sendEmail that you are allowed
Messaging.sendEmail(allMails); 

sendEmail can be called on an array of messages, so rather than call it once you should build up an array of singleemailmessage and then send them all in one call.


Edit A couple more things you can try to understand what the problem is

Before you make the sendEmail call, add

System.debug('You have made ' + Limits.getEmailInvocations() + ' email calls out of ' + Limits.getLimitEmailInvocations() + ' allowed');

When you look at the log you should see

You have made 1 email calls out of 10 allowed

If you see a series of messages (1,2,3 etc.) then you are calling it in a loop.

You can also check that there is capacity out of the 5,000 daily allowance still available (only if you are on a Winter '14 instance).

try {
    Messaging.reserveSingleEmailCapacity(emailsLeads.size());
} catch (Exception e) {
    // From Winter '14, this code is now executed.
    System.debug('You have used up your daily allowance of mails');
}

Update - From Winter'17, limits have been raised to 5,000 instead of 1,000.

10
  • can you please tell me what same context means here..is it in the same transaction you are talking about..in a single run???
    – miku
    Commented Sep 24, 2013 at 8:15
  • As you are running a batch process, each batch executes in a fresh context with a fresh set of limits.
    – Doug B
    Commented Sep 24, 2013 at 8:45
  • yes... i am running a batch process...Also i am only sending 1 email/context...i am just passing a list to batch class.. and sending emails.. String query='Select id from Lead limit 1'; Batch_send_emails bse=new Batch_send_emails(); bse.query=query; bse.resendEmails=emailList; database.executebatch(bse);
    – miku
    Commented Sep 24, 2013 at 8:51
  • 1
    i got this in salesforce limits pdf.....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.
    – miku
    Commented Sep 24, 2013 at 9:02
  • Can you post a little more of your code, the full method that you are sending emails from?
    – Doug B
    Commented Sep 24, 2013 at 9:31
11

Single Messaging has limits as you cannot call sendEmail method more than 10 times in single transaction and 1000 e-mail per license per day. Some how you are hitting these limits.

If you are sending email to organization internal users in that case you should use setTargetObjectId(userId) instead of toAddress. Pass user Id in that method.

setTargetObjectId(userId) doesn't count against Salesforce governor limits.

2
  • 2
    For me that is the best answer to not have such limitation. Commented Feb 4, 2015 at 8:04
  • @AshwaniI have a doubt if I use a template in then how to use targetObjectId
    – Pavan tej
    Commented Sep 11, 2018 at 13:38
9

I can confirm Salesforce changed the daily limit for Developer Edition orgs to 10 a few releases ago, this is indeed a significant drop from the before 1000. It caused issues with our development and testing teams. Eventually we made a case to get it raised back up to 1000 for some of our DE orgs, suggest you contact support and request the same, at least for your test orgs. It might also be worth raising an Idea to ask Salesforce to review this decision.

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

3

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

If you carefully read this document the email limit for a day is 1000 emails/day but the problem is you are hitting context limit.

In a single context you can just send 10 emails through SendEmail().So i am sure you are triggering this through trigger and for bulk load its failing

Messaging.sendEmail(new Messaging.Email[] { mail } , opt_allOrNone);

Instead of this what i generally follow is through trigger stamp a boolean variable on satisfying criteria for sending mails and use workflow as alternative to send mails based on Boolean check .

2
  • In a single context you can make 10 calls of SendEmail(), but each call can send many emails by passing an array as the argument.
    – Doug B
    Commented Sep 24, 2013 at 7:35
  • Also i am not more than 10 emails in a single context ..I am sending a single email/context..still after 10-12 emails i am getting single email limit exceeded..
    – miku
    Commented Sep 24, 2013 at 8:33
1

By defining the Single Message as below, you can send only one email at a time. If you want to send 10 emails, it is 10 instances of the single message.

Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();

Change your definition as follows.

List< Messaging.SingleEmailMessage > mail = new List< Messaging.SingleEmailMessage >();

By doing so, you can add 100 members to the list. All the 100 emails are sent with the method Messaging.SendEmail(mail);

1

For all the people hoping to query the Email limit remaining you can use the OrgLimits class -

Map<String,System.OrgLimit> limitsMap = OrgLimits.getMap();
System.OrgLimit emailLimit = limitsMap.get('SingleEmail');
System.debug('Limit Name: ' + emailLimit.getName());
System.debug('Usage Value: ' + emailLimit.getValue()); // will show currently used up limit
System.debug('Maximum Limit: ' + emailLimit.getLimit());

For the OP, you can check to see if the Maximum Limit - Usage Value > 0 before sending the emails and also ensuring you do not do more than 10 email invocations per transaction (ie. calling the Messaging.sendEmail method).

Reference - https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_class_System_OrgLimits.htm#apex_class_System_OrgLimits

2
0

The Email Limits were lowered in Developer Edition organizations to reduce abuse. If you need higher limits, please open a case with support and explain your situation.

You must log in to answer this question.

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