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
Jayanth G 3Jayanth G 3 

Send 200 mails to the List of records in Custom Object

Hello,

I am executing below code in an Apex Batch
The Query returns a list of 200 records and stores it in scope. 

My Code is getting executed successfully, even after checking debug logs, there is no exceptions or any error. But the problem here is mails are getting delivered to only first few records in the list and none of the others are receiving the mails. 

I went to workbench and checked the mail limits are decreasing from 1000 to 800. But only few ppl are getting the mails and others aren't. Below is the sample code.

 

List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>();

for(Service_Resource__c sr : (List<Service_Resource__c>)scope) {
Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
                if(owa.size()>0){
                       email.setOrgWideEmailAddressId(owa[0].Id);    
                }
                else{
                    email.setSenderDisplayName('NoReply-ActNow');
                }
                email.setSubject(htmlsubject1NonSFUsers);
                email.setToAddresses(new String[] {sr.Email__c});
                email.setSaveAsActivity(false);
                email.setHtmlBody(htmlbody1NonSFUsers);
                email.setTemplateId(nonSFUsersEmailTemplate.Id);
                mails.add(email);
}
if(mails.size()>0){
      Messaging.sendEmail(mails);
}
Requesting you to help me out here to find out why the emails are not getting delivered to everyone even though the email limits are not over.

Thank you
 
mukesh guptamukesh gupta
Hi Jayanth,


You need to check email Id for user's  that's not receving email,   may be these user email appended with '.invalid'

https://help.salesforce.com/s/articleView?id=000333417&type=1 (https://help.salesforce.com/s/articleView?id=000333417&type=1)

Email Limits in Salesforce:
  • Based on Greenwich Mean Time (GMT), you can send mass email up to a maximum of 5,000 external email addresses per day per org.
  • The single, as well as mass email limits, do not count unique addresses as one into account. For example, if you have mukesh@example.com in your email 10 times, that counts as 10 against to the limit.
  • You can send as many amounts of email you want to your org’s internal users including portal users.
  • You can send mass email messages only to contacts, person accounts, leads, as well as your org’s internal users.
  • In Developer Edition orgs and orgs evaluating Salesforce during a trial period, you can send maximum 10 mass email to external email addresses per day.
if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh