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
Madhu007Madhu007 

Single Email Limit from Apex

Hi,

I got the below error while sending email from apex class.
SendEmail failed. First exception on row 0; first error: SINGLE_EMAIL_LIMIT_EXCEEDED, Failed to send email: []
How can i solve this. 

Thanks.
 
ManojjenaManojjena
Hi Madhu,

I think you are sending Email inside for loop .So to avoid the error you need to create a list and use Messaging.sendEmail method from Messaging .

List<Messaging.SingleEmailMessage> emailList=List<Messaging.SingleEmailMessage>();
for(){
  SingleEmailMessage emil=new SingleEmailMessage();

emailList.add(email);
}
Messaging.sendEmail(emailList);

Try to implement like above and let me know any issue .
Madhu007Madhu007
Hi Manoj,

Thanks for the reply. Senidng email is not in the for loop. Still i am getting error.

Thanks.  
ManojjenaManojjena
Hi Madhu,
It is possible to post your code ,I will check and try to resolve your issue .
Madhu007Madhu007
Hi Manoj. Thanks for the repy. Please find the code here.

Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage(); 
        
        PageReference pdf =  Page.ServiceAgreementPDF;
        pdf.getParameters().put('id',(String)contract.id); 
        pdf.setRedirect(true);

        Blob b = pdf.getContent();

        Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
        efa.setFileName('attachment.pdf');
        efa.setBody(b);

        String addresses;
        addresses = Contract.Contact_Email__c;
        
        
        String cc;
        cc= 'contract@29bc1783p1qsovuawyusriie5t3kl29j4x69c1fmuosj13ix4t.9-10o2ceau.ap1.apex.salesforce.com';
        
       
        String[] toAddresses = addresses.split(':', 0);
        String[] ccAddresses = cc.split(':', 0);
        
        email.setSubject( subject );
        email.setToAddresses( toAddresses );
        email.setCcAddresses( ccAddresses );
        email.setPlainTextBody( body );
        email.setTargetObjectId(UserInfo.getUserId());
        email.saveAsActivity = false;
        email.setFileAttachments(new Messaging.EmailFileAttachment[] {efa});

        
        Messaging.SendEmailResult [] r = 
            Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});  

Please help.