+ Start a Discussion
KunlunKunlun 

Sending email error in apex: "Too many Email Invocations: 1"

Hi All

 

I wrote apex code to send email as below, but it threw error "Too many Email Invocations: 1". I searched on internet, it said the sending email limitation is 10, but I can not send 1 email. It really made me crazy. Should I make some configuration to open email sending service in SFDC?

 

Thanks

Kunlun

public with sharing class PortalTestController{
    public PageReference dataRequest(){
        sendRequestEmail();
        return null;
    }
    public void sendRequestEmail(){
        //Messaging.reserveSingleEmailCapacity(10);            
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        String[] toAddresses = new String[] {'kunlun.software@gmail.com'};
        String[] ccAddresses = new String[] {'kunlun.software@gmail.com'};
        mail.setToAddresses(toAddresses);
        mail.setCcAddresses(ccAddresses);
        mail.setReplyTo('kunlun.software@gmail.com');
        mail.setSenderDisplayName('Salsforce');
        mail.setSubject('Salsforce Email');
        mail.setBccSender(false);
        mail.setUseSignature(false);
        mail.setPlainTextBody('xxxx');        
        mail.setHtmlBody('xxxx');
        Messaging.sendEmail(new Messaging.SingleEmailMessage[]{mail});        
    }         
}

 

<apex:page controller="PortalTestController" sidebar="false" showHeader="false" standardStylesheets="true" readOnly="true" >
    <apex:form >

    <apex:commandButton action="{!dataRequest}" value="Download Your Data" />
</apex:form>
</apex:page>

 

Jerun JoseJerun Jose

The limit of 10 emails is for the entire transaction.

 

Is your email sending block inside some loop or is it recursively called ??

Anup JadhavAnup Jadhav

Is this inside a loop or a trigger? Have you bulkified your code?

 

- Anup

KunlunKunlun

I posted the original code, there are no loop.

 

And I changed a new salesforce account and try my code, it worked fine. So I guess there are some configuration or limitation for my working sf account.

sumilsumil

Hi Kunlun, 

 

I am facing same problem with same condition, did u solve ur problem. please advise me also.

 

one alternate soluction which i do is that i remove "Read Only" = true from page. then it is woking fine. i am not able to understand what is relation between Read Only attribute to send email function 

 

Thanks !

 

Suneel Mishra