How to run a scheduled job every 15 mins?
You can write a Batch Class and then Schedule it with the help of a scheduler.Let me explain it to you with the help of an example:
BATCH CLASS :
global class test_BATCH implements Database.Batchable<sObject> {
global (Database.QueryLocator | Iterable<sObject>) start(Database.BatchableContext BC) {
String query = 'SELECT Id,Name FROM Account';
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, List<Account> scope) {
for(Account a : scope){
a.Name = a.Name + 'Updated';
}
update scope;
}
global void finish(Database.BatchableContext BC) {
}
}
SCHEDULABLE CLASS :
global class scheduledBatchable implements Schedulable{
global void execute(SchedulableContext sc) {
test_BATCH b = new test_BATCH();
//Parameters of ExecuteBatch(context,BatchSize) database.executebatch(b,10);
}
}
***Note: if batch size is not mentioned it is 200 by default.
CUSTOM TIMING
String time = '0 0 * * * ?';
SheduledBatchable sch = new scheduledBatchable();
system.schedule('Hourly Example Batch Schedule job', time, sch);
*****If you want to run it as frequent as 15,30 or N mins .....
String time = '0 15 * * * ?' ;
String time = '0 30 * * * ?' ;
System.schedule('Scheduled Job 1', '0 0 * * * ?', new ScheduledClass());
ReplyDeleteSystem.schedule('Scheduled Job 2', '0 15 * * * ?', new ScheduledClass());
System.schedule('Scheduled Job 3', '0 30 * * * ?', new ScheduledClass());
System.schedule('Scheduled Job 4', '0 45 * * * ?', new ScheduledClass());