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
Pradeep dPradeep d 

Hi, Batch Apex issue

I have to send 1 lakh emails in one transaction, for that i used batch, but day limit is 5000, how can i continue that rest of the emails to next day
Best Answer chosen by Pradeep d
Amit Chaudhary 8Amit Chaudhary 8
Please check below post for same issue
1) https://salesforce.stackexchange.com/questions/153331/using-batch-scheduling-for-mass-emails-apex

You Can use Marketing Cloud (ET) for same as well
 

All Answers

venu parasavenu parasa
Hi Pradeep,

You can acheive this by scheduling.
Pradeep dPradeep d
I mean how batch separates sent mail records, pending mails to send ..?
Pradeep dPradeep d

Here is my batch 

global class mailsend implements Database.Batchable <sobject>, Database.Stateful{

   // global List<string> mailx;
    public id mailid;
    public string mailx;
    public string dumname;
    public string urlcode;
    public List<Contact> Slist;
    public string messageBody;    
    public string queryString = '';
    public set<Id> setIds = new set<Id>();
    
    public mailsend(){}
    
   public mailsend(id DummyconId, string dummymail, string dummyname,   List<Contact>SelectedDc ) {   
       mailid = DummyconId;
       mailx  = dummymail;
       dumname = dummyname;
       this.Slist  = SelectedDc ;
        
      // EmailTemplate templateId = [Select id from EmailTemplate where name = 'Sales: New Customer Email'];   
   }

    global Database.QueryLocator start(Database.Batchablecontext Bc){    
       queryString += ' Where Id IN: setIds ';  
        return Database.getQueryLocator(queryString);
    }

    global void execute(Database.Batchablecontext Bc, List<Dummy_Contact__c> Scope){
            ContactUpdateURL__c mc = ContactUpdateURL__c.getall().values();
         urlcode = mc.URLforContactUpdate__c;   
        Map<id, String> mMap = new Map<id, String>();        
        List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>();
       For(Dummy_Contact__c dc: Scope){               
            
         String body = '' ;
          //Creating tabular format for the case details
          body = '<html><body>Dear '+dc.name+',<br><br> '+  + 
                                            
                                           'I' + 'm currently updating my contact database and want to make sure I have your current data right.' + +
                                                    
                                           'Could you have a quick look at below info? If you would like to change or update certain information, just click the ' + 'Update Now' + ' link on the bottom of the email and save your changes when done.<br> <br>' + +
                                           
                                     
                                             'Many thanks in advance, ' +'<br>' + +

                                            
                                           '' + UserInfo.getlastname() +' </html></body>';
        
          Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage() ;
          String[] toAddresses = new String[] {dc.Email__c} ;
          mail.setToAddresses(toAddresses) ;
          mail.setSubject('Touch Contact');
          mail.setHtmlBody(body);
          mails.add(mail);          
        }
        Messaging.sendEmail(mails);
    }
    
    global void finish(Database.Batchablecontext Bc){}
}

Amit Chaudhary 8Amit Chaudhary 8
Please check below post for same issue
1) https://salesforce.stackexchange.com/questions/153331/using-batch-scheduling-for-mass-emails-apex

You Can use Marketing Cloud (ET) for same as well
 
This was selected as the best answer