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
Kashif Ali 56Kashif Ali 56 

single email limit exceeded exception: Fails to send more than 15 emails in one transaction

Hi

following is my code:

public PageReference sendEmailMethod(){
        List<Messaging.SingleEmailMessage> message = new List<Messaging.SingleEmailMessage>();
        try{
            update email;
        }catch(Exception e){
            ApexPages.addMessage(new ApexPages.message
            (ApexPages.severity.Warning,'An error occured while sending email'+e));
            return null;
        }
        String body = '';
        for(integer i=0;i<wrapperBooks.size();i++){
            if(wrapperBooks[i].isSelected == true){
                Messaging.SingleEmailMessage msg = Messaging.renderStoredEmailTemplate(email.Id, wrapperBooks[i].book.Author__r.Id, wrapperBooks[i].book.Author__r.Id);
                msg.setTargetObjectId(wrapperBooks[i].book.Author__r.Id);
                msg.setSaveAsActivity(false);
                message.add(msg);
            }
        }
        system.debug('--->'+message.size());
        System.debug('You have made ' + Limits.getEmailInvocations() + ' email calls out of ' + Limits.getLimitEmailInvocations() + ' allowed');
        try{
            Messaging.sendEmail(message);
            System.debug('Email sent Success fully to:'+message.size());
            PageReference ref = new PageReference('/apex/booksDetails');
            ref.setRedirect(true);
            return ref;
        }
        catch(Exception e){
            ApexPages.addMessage(new ApexPages.message
            (ApexPages.severity.Warning,'An error occured while sending email'+e));
            return null;
        }
    }

Can someone tell me how to fix this. I want to send bulk emails. I am in my developer org.
 

Team NubesEliteTeam NubesElite
Hi Kashif,
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 the account, contact, lead, opportunity, case, campaign, or custom object pages.

Thank You
www.nubeselite.com
Development | Training | Consulting


Please mark this as solution if your problem resolved.


 
Kashif Ali 56Kashif Ali 56
Hi Team NubesElite
I know what the limits are but i get an exception when targetObject ID of 16th email is set.
Can you tell me what is the reason
Thank you
Ajay K DubediAjay K Dubedi
Hi Kashif,

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

In Developer Edition organizations and organizations evaluating Salesforce during a trial period, your organization can send a 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.

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.

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).


I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Ajay Dubedi
www.ajaydubedi.com  (http://www.ajaydubedi.com )