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
yaramareddy radhikayaramareddy radhika 

How many emails we can send from finish method in Batch apex,Mention the limit if they are any?

NagendraNagendra (Salesforce Developers) 
Hi Radhika,

May I suggest you please check with below code for the same which might help you accelerate further with above requirement.
global class batchupdate implements Database.Batchable<sobject>,Database.Stateful
    global List<Transaction__c> Trans_List;
&nbsp; &nbsp;// list<account> s{set;get;}
&nbsp; &nbsp; global Database.QueryLocator start(Database.BatchableContext bc)
&nbsp; &nbsp; {
&nbsp; &nbsp; &nbsp; &nbsp; String Query = &nbsp;'select id,Transaction_type__c,amount_info__c from Transaction__c';
&nbsp; &nbsp; &nbsp; &nbsp; System.debug('------Query---->'+Query);
&nbsp; &nbsp; &nbsp; &nbsp; return Database.getQueryLocator(Query);
&nbsp; &nbsp; }
&nbsp; &nbsp; global void execute(Database.BatchableContext bc,list<Transaction__c> scope)
&nbsp; &nbsp; {
&nbsp; &nbsp; &nbsp;// s=new list<account>();
&nbsp; &nbsp; &nbsp; &nbsp; list<Transaction__c> cust=new List<Transaction__c>();
&nbsp; &nbsp; &nbsp; &nbsp; System.debug('------scope---->'+scope.size());
&nbsp; &nbsp; &nbsp; &nbsp;// scope=s;
&nbsp; &nbsp; &nbsp; &nbsp; for(Transaction__c c:scope)
&nbsp; &nbsp; &nbsp; &nbsp; {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; c.amount_info__c=5656;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cust.add(c);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// &nbsp;system.debug(cust);
&nbsp; &nbsp; &nbsp; &nbsp; }

&nbsp; &nbsp; &nbsp; &nbsp; update cust;
&nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; }
&nbsp; &nbsp; global void finish(Database.BatchableContext bc)
      //create body for email

      String BodyText = '';

&nbsp;     for(Transection__c ts : Trans_List)
&nbsp;     {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; BodyText += '***********************************************'+'\n'; &nbsp;&nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; BodyText += '***********************************************'+'\n';
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; BodyText += YOUR DETAILS FROM CURRENT RECORD; //ts.FIELDNAME__C &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;


&nbsp; &nbsp; Messaging.SingleEmailMessage mail1=new Messaging.SingleEmailMessage();
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; String[] toadd=new String[]{''};
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;mail1.setToAddresses(toadd);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mail1.setSubject('Test mail');
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mail1.setPlainTextBody('this is a test mail');
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Messaging.SingleEmailMessage mail2=new Messaging.SingleEmailMessage();
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mail1.setToAddresses(toadd);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mail1.setSubject('Test mail');
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mail1.setHtmlBody(BodyText);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Messaging.sendEmail(new Messaging.singleEmailMessage[]{mail1});
&nbsp; &nbsp; }

&nbsp; &nbsp; &nbsp;

There are two things which I have added. 

1. Database.Stateful interface at the top which will maintain state throughout the execution
2. global Trans_List which can be used to retain record so that we can get the processed record in finish method.

For information on governor limits please check with below links: Hope this helps.