New Batch#100 (10th Nov 2021) - Salesforce Admin + Dev Training (WhatsApp: +91 - 8087988044) :https://t.co/p4F3oeQagK

Showing posts with label system.schedule. Show all posts
Showing posts with label system.schedule. Show all posts

Wednesday, 17 October 2012

Scheduling Batch Class after 6 minutes whenever a batch finish method executed in salesforce

AsyncApexJob a = [SELECT Id, Status, NumberOfErrors, JobItemsProcessed,
         TotalJobItems, CreatedBy.Email
         FROM AsyncApexJob WHERE Id =:BC.getJobId()];

* Above syntax is to retrieve information regarding to the jobs.
             Batch_classname bs = new Batch_classname();
             Datetime sysTime = System.now();
             sysTime = sysTime.addminutes(6);
             String chron_exp = '' + sysTime.second() + ' ' + sysTime.minute() + ' ' +
             sysTime.hour() + ' ' + sysTime.day() + ' ' + sysTime.month() + ' ? ' + sysTime.year();           
             System.schedule('Update Actual'+sysTime.getTime(),chron_exp, bs);

Tuesday, 16 October 2012

Scheduling batch class for every 5 minutes using system.schedule method in salesforce

Batch_scheduledclassname bs = new Batch_scheduledclassname bs();
String sch = '0 6 * * * ? ';
System.schedule('My Job1', sch, bs);

Note: While writing schedular class don't forget to use datebase.executeBatch method which inturn will run the apex batch class.
* Above 6 means every hour 6th minute.
* If you want to schedule the calss for every 5 minutes then you need paste above code with some changes for 10 times in developer console.
* Changes are:
- instead of 6 replace with 12,18,24..... like that.
- Change the Batch Job name My Job1 to some other name whenever we want to submit new job

Labels