Loading

'Too many API email invocations 11' error when sending emails via Apex

게시 일자: Oct 13, 2022
상세 설명
There is no email limit from Apex. The limit is on the number of times the sendEmail() method can be invoked from Apex.  We will not be having a limit for Emails from Apex, however, we will be having the limit for number of times the sendEmail() method can be invoked from Apex in a transaction. 

 

Best practice is to ensure that you're not calling the sendEmail() method inside a for loop

솔루션

 

Sample code for SendEmail()

NOTE: The code provided below is an example. You should always test code before pushing to production.

//method to send mail to a list of users
public static void DispatchEmail() {
    List lstMails = new List();
      lst = 20;
       for(Integer i : lst) {
          Messaging.SingleEmailMessage message = getEmail();       
 //Construct the email message here by populating the values such as body, subject
                //Adding emails to the list       
 lstMails.add(message);
    }  
   //Sending the email list in a single call.
    Messaging.sendEmail(lstMails);
  }

 
public static Messaging.SingleEmailMessage getEmail() {
    Messaging.SingleEmailMessage mailMessage = new Messaging.SingleEmailMessage();
    mailMessage.setSaveAsActivity(false);
    return mailMessage;
  }
Knowledge 기사 번호

000385111

 
로드 중
Salesforce Help | Article