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
samruddhi podesamruddhi pode 

I am trying to send email message in batch class after successfully updation of field. Batch class is running fine but receipient not receiving any email message

Batch class:

public class MyBatchable implements Database.Batchable<SObject> {

    public Database.QueryLocator start(Database.BatchableContext context) {
        return Database.getQueryLocator([select Id from Account order by Name]);
    }

    public void execute(Database.BatchableContext context, List<Account> scope) {
        Account[] updates = new Account[] {};
        for (AggregateResult ar : [
                select AccountId a, count(Id) c
                from Contact
                where AccountId in :scope
                group by AccountId
                ]) {
            updates.add(new Account(
                    Id = (Id) ar.get('a'),
                    No_of_Contacts__c = (Decimal) ar.get('c')
                    ));
        }
                update updates;
               
              }
             
   public void finish(Database.BatchableContext context) {
   
           Account[] updates = new Account[] {};
     Database.SaveResult[] srList = Database.update(updates,false);
                  Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
                  String[] toAddresses=new String[]{'123podesamruddhi@gmail.com'};
                for( Database.SaveResult r:srList)
                {
                if (r.isSuccess()) {
              
               
                 mail.setToAddresses(toAddresses);
                 mail.setSubject('Batch class run and field updated');
                 mail.setPlainTextBody('The field Number of contacts on object Account is updated successfully');
                // lstEmail.add(mail);
                Messaging.sendEmail(new Messaging.SingleEmailMessage[]{mail});
                 }
                 else{
                 for(Database.Error re:r.getErrors())
                 {
                 system.debug(re);
                     mail.setToAddresses(toAddresses);
                     mail.setSubject('Batch class run but field not updated');
                        mail.setPlainTextBody('The field Number of contacts on object Account is failed to update');
                     Messaging.sendEmail(new Messaging.SingleEmailMessage[]{mail});

                 }
                 }
    }
    }

}


What should i do?
Nayana KNayana K
Check if https://help.salesforce.com/HTViewHelpDoc?id=emailadmin_deliverability.htm Acces level is 'All Email'