You need to sign in to do that
Don't have an account?
![k sfdc k sfdc](https://dfc-org-production.my.site.com/img/userprofile/default_profile_45_v2.png)
URGENT:How to solve below Batch class Error(MASS_MAIL_LIMIT_EXCEEDED, Failed to send email) ?
ERROR:
First error: SendEmail failed. First exception on row 1; first error: MASS_MAIL_LIMIT_EXCEEDED, Failed to send email
Batch class:
------------------
global class MyBatchClass implements Database.Batchable<sObject> { global Database.QueryLocator start(Database.BatchableContext bc) {
Date d= Date.today();
String soqlQuery = 'SELECT id,name,Owner.Email,Owner.Name,Expiry_Date__c FROM Account WHERE Expiry_Date__c < :d'; return Database.getQueryLocator(soqlQuery);
}
global void execute(Database.BatchableContext bc, List<Account> accountList)
{
List<Messaging.SingleEmailMessage> mailList = new List<Messaging.SingleEmailMessage>();
for(Account acc: accountList)
{
List<String> toAddresses = new List<String>();
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
toAddresses.add(acc.Owner.Email);
mail.setToAddresses(toAddresses);
mail.setSubject('Welcome to Sweet 16 Siebel Batch');
String messageBody = '<html><body>Hi ' + acc.Name + ',<br>Your account Expires today. <br>Kindly contact your administrator.<br><br><b>Regards,</b><br>Mahesh k</body></html>';
mail.setHtmlBody(messageBody);
mailList.add(mail);
}
Messaging.sendEmail(mailList);
}
global void finish(Database.BatchableContext bc) { } }
Schedule Class:
------------------------
global class ScheduleBatchClassForSendEmail implements Schedulable{
global void execute(SchedulableContext sc) {
MyBatchClass schedulejob = new MyBatchClass();
database.executebatch(schedulejob); } }
First error: SendEmail failed. First exception on row 1; first error: MASS_MAIL_LIMIT_EXCEEDED, Failed to send email
Batch class:
------------------
global class MyBatchClass implements Database.Batchable<sObject> { global Database.QueryLocator start(Database.BatchableContext bc) {
Date d= Date.today();
String soqlQuery = 'SELECT id,name,Owner.Email,Owner.Name,Expiry_Date__c FROM Account WHERE Expiry_Date__c < :d'; return Database.getQueryLocator(soqlQuery);
}
global void execute(Database.BatchableContext bc, List<Account> accountList)
{
List<Messaging.SingleEmailMessage> mailList = new List<Messaging.SingleEmailMessage>();
for(Account acc: accountList)
{
List<String> toAddresses = new List<String>();
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
toAddresses.add(acc.Owner.Email);
mail.setToAddresses(toAddresses);
mail.setSubject('Welcome to Sweet 16 Siebel Batch');
String messageBody = '<html><body>Hi ' + acc.Name + ',<br>Your account Expires today. <br>Kindly contact your administrator.<br><br><b>Regards,</b><br>Mahesh k</body></html>';
mail.setHtmlBody(messageBody);
mailList.add(mail);
}
Messaging.sendEmail(mailList);
}
global void finish(Database.BatchableContext bc) { } }
Schedule Class:
------------------------
global class ScheduleBatchClassForSendEmail implements Schedulable{
global void execute(SchedulableContext sc) {
MyBatchClass schedulejob = new MyBatchClass();
database.executebatch(schedulejob); } }
Mass email messages sent with the sendEmail method count against the sending organization's daily mass email limit. When this limit is reached, calls to the sendEmail method using MassEmailMessage are rejected, and the user receives a MASS_MAIL_LIMIT_EXCEEDED error code.
If you wish to know in advance as to whether this limit will be it or not - try the option given in the below thread:
https://developer.salesforce.com/forums?id=906F000000092R6IAI