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
Saswat MohantySaswat Mohanty 

single email notification for all batch class job finish

Hi all,

We have 2 batch classes developed on contact and on one custom object. If everytime these 2 objects are updated, the batch class runs showing the progress which we are showing in a visualforce page.

Also, we have designed a mail template in class so that everytime the batch jobs are finished the email will be triggered. However, we want to limit the no. of emails at regular intervals. So, how can we receive a single email at the end of the day for every batch class/job sectionwise?
Rahul BorgaonkarRahul Borgaonkar
Hi,

My thought on this...
-Store your update progress in contact and custom object in a seperate variable.
-Write a schedule class which will read this progress and send a mail.
-Execute this schedule class at a specific time everyday.

Best Regards,

Rahul
 
Saswat MohantySaswat Mohanty
Thanks for your information. I have started with the below approach

global class batchmailtrigger implements Schedulable{
 
 // Execute method
    global void execute(SchedulableContext SC) {
    
 
 batchContactUpdate c1 = new batchContactUpdate ();
 batchBrandUpdate b1 = new batchBrandUpdate ();
    
    database.executebatch(c1,10);
    database.executebatch(b1,10);
   
  datetime nextScheduleTime = system.now().addMinutes(60);
      string minute = string.valueof(nextScheduleTime.minute());
      string second = string.valueof(nextScheduleTime.second ());
      string cronvalue = second+' '+minute+' * * * ?' ;
      string jobName = 'batchmailtrigger' +
  nextScheduleTime.format('hh:mm');
 
    batchmailtrigger p = new batchmailtrigger ();
    system.schedule(jobName, cronvalue , p);
 
    
    system.abortJob(sc.getTriggerId());//Aborting the Job
 
   }
 }

But I think i can put a mail template in this scheduler instaed of in batch class. However, i am thinking that I am missing the variable store.

is that true?
Rahul BorgaonkarRahul Borgaonkar
Hi,

I am not sure if you can put below part in execute function
////
 batchmailtrigger p = new batchmailtrigger ();
    system.schedule(jobName, cronvalue , p);
     system.abortJob(sc.getTriggerId());//Aborting the Job
////
It should be executed from Execute Ananymous Window.

Have creating fields to store progress of contact and custom object?
Also please clarify, need of below statements. Are you using batch here?
///
 batchContactUpdate c1 = new batchContactUpdate ();
 batchBrandUpdate b1 = new batchBrandUpdate ();
 database.executebatch(c1,10);
 database.executebatch(b1,10)
////


Regards,

Rahul