You need to sign in to do that
Don't have an account?

Apex Emails
HI
Below is my code.
public class LeadEmail
{
public static void SendEmailTolead(list<lead> lstLead)
{
if(! lstLead.isEmpty())
{
list<messaging.SingleEmailMessage> lstEmails = new list<messaging.SingleEmailMessage>();
for(lead lr : lstLead)
{
messaging.SingleEmailMessage email = new messaging.SingleEmailMessage();
string[] toEmailsIds = new string[]{lr.Email};
email.settoAddresses(toEmailsIds);
email.setSenderDisplayName('lead Record Creation Alert');
email.setReplyTo('support@RFI.com');
string emailsubject = 'congralutions'+lr.Name+'you have been registerd';
email.setSubject(emailsubject);
string emailHTMLContent = 'Dear'+lr.name+',<br/> <br/>'+
'<br/><br/> here are your details... <br/><br/>'+
'<br/> Your Company....'+lr.Company+
'<br/> Your tile for the Role'+lr.Title+
'<br/> your Status for The record'+lr.Status+
'thanks & Regards';
email.setHtmlBody(emailHTMLContent);
lstEmails.add(email);
}
if(!lstEmails.isempty())
{
Messaging.sendEmail(lstEmails); }
}
}
}
Execute window
list<lead> lstLead = [select id,name,email,company,title,status from lead];
LeadEmail.SendEmailTolead(lstLead);
Getting error
Line: 38, Column: 1
System.EmailException: SendEmail failed. First exception on row 5; first error: SINGLE_EMAIL_LIMIT_EXCEEDED, Email limit exceeded: []
Any assistance
Thanks in advance
Below is my code.
public class LeadEmail
{
public static void SendEmailTolead(list<lead> lstLead)
{
if(! lstLead.isEmpty())
{
list<messaging.SingleEmailMessage> lstEmails = new list<messaging.SingleEmailMessage>();
for(lead lr : lstLead)
{
messaging.SingleEmailMessage email = new messaging.SingleEmailMessage();
string[] toEmailsIds = new string[]{lr.Email};
email.settoAddresses(toEmailsIds);
email.setSenderDisplayName('lead Record Creation Alert');
email.setReplyTo('support@RFI.com');
string emailsubject = 'congralutions'+lr.Name+'you have been registerd';
email.setSubject(emailsubject);
string emailHTMLContent = 'Dear'+lr.name+',<br/> <br/>'+
'<br/><br/> here are your details... <br/><br/>'+
'<br/> Your Company....'+lr.Company+
'<br/> Your tile for the Role'+lr.Title+
'<br/> your Status for The record'+lr.Status+
'thanks & Regards';
email.setHtmlBody(emailHTMLContent);
lstEmails.add(email);
}
if(!lstEmails.isempty())
{
Messaging.sendEmail(lstEmails); }
}
}
}
Execute window
list<lead> lstLead = [select id,name,email,company,title,status from lead];
LeadEmail.SendEmailTolead(lstLead);
Getting error
Line: 38, Column: 1
System.EmailException: SendEmail failed. First exception on row 5; first error: SINGLE_EMAIL_LIMIT_EXCEEDED, Email limit exceeded: []
Any assistance
Thanks in advance
Add below line also:
email.setSaveAsActivity( false );
Thanks,
Maharajan.C
All Answers
There is a limit on the number of emails you can send from Apex, this is 5,000 per 24 hours.
Check this Link:-
https://help.salesforce.com/articleView?id=000323568&language=en_US&type=1&mode=1 (https://help.salesforce.com/articleView?id=000323568&language=en_US&type=1&mode=1)
In case you find any other issue please mention.
If you find your Solution then mark this as the best answer.
URL: https://help.salesforce.com/articleView?id=000331939&mode=1&sfdcIFrameOrigin=null&type=1
From time to time organizations may hit their SingleEmailMessage limit. When this happens, you will see the following email message:
'SINGLE_EMAIL_LIMIT_EXCEEDED, The daily limit for the org would be exceeded by this request'
Note: This limit applies only to email messages composed and sent through the API or Apex. This is not trackable currently in 'Setup.' However, there is a convenient way to track the limits and usage for the organization, using the Workbench tool.
Resolution
Use Workbench to track organization limits and usage
1. Ensure you are logged into the organization where you want to verify your limits.
2. Navigate to: https://workbench.developerforce.com/login.php
3. Accept any oauth prompts to complete authentication
4. On the 'Jump to' picklist select REST Explorer.
5. Click Select.
6. From the options presented select: /services/data/vXX.0/limits
7. Click Execute.
8. Select the SingleEmail area to view the daily maximum and remaining calls.
Notes:
SingleEmailMessage calls are calculated for a 24 hour period from 12 midnight UTC (00:00) - the limit will reset to zero at this time each day.
Emails to each recipient are counted, such as addresses in the 'to' and 'cc' email fields.
There is a default value for each organization. the limit is not related to license count.
Have you tried checking the limits in your sandbox?
Naveen
Add the setTargetObjectId as cusrrent user info. May it will help you.
email.setTargetObjectId( UserInfo.getUserId() );
https://salesforce.stackexchange.com/questions/130447/how-can-be-avoided-error-single-email-limit-exceeded-email-limit-exceeded-if-nee
https://salesforce.stackexchange.com/questions/17133/single-email-limit-exceeded-salesforce-very-frequently/17143#17143
Thanks,
Maharajan.C
When trying to implement your changes getting an error
Line: 40, Column: 1
System.EmailException: SendEmail failed. First exception on row 0; first error: INVALID_SAVE_AS_ACTIVITY_FLAG, saveAsActivity must be false when sending mail to users.: [saveAsActivity, true]
Add below line also:
email.setSaveAsActivity( false );
Thanks,
Maharajan.C
Can you help me with a test class for it
Add if there is any other fields are required to create the Lead. Change the lead status as per your org.
Thanks,
Maharajan.C