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 * * * ?' ;

Comments

  1. System.schedule('Scheduled Job 1', '0 0 * * * ?', new ScheduledClass());
    System.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());

    ReplyDelete

Post a Comment

Popular posts from this blog

Adding a red asterisk to required fields using label in LWC

The Developer Console didn't set the DEVELOPER_LOG trace flag on your user. Having an active trace flag triggers debug logging. You have 1,978 MB of the maximum 1,000 MB of debug logs. Before you can edit trace flags, delete some debug logs.

Salesforce: Serial and Parallel Approval