0

I have a batch class which I had scheduled to run every Hours as below:

Batchclass obj = new Batchclass();
String cron = '0 0 0/1 1/1 * ? *';
System.schedule('Batchclass Job',cron,obj);

But now I want to run it every 30 min. So I tried this cron string : 0 0/30 * 1/1 * ? * but I got error : Seconds and minutes must be specified as integers: 0 0/30 * 1/1 * ? *

So I googled a bit and found a solution where I have to run 2 jobs to achieve this as below:

Batchclass obj = new Batchclass();
System.schedule('Batchclass Job1', '0 0 * * * ?',obj);
System.schedule('Batchclass Job2', '0 30 * * * ?',obj);

But this solution will create 2 Batch jobs which i am hoping to avoid. Any Solutions?

1
  • Comments are not for extended discussion; this conversation has been moved to chat.
    – Adrian Larson
    Commented Dec 5, 2017 at 13:47

1 Answer 1

2

Short of using "Suicide Scheduling", which requires modifying the code, you need two jobs. You can't schedule in increments of less than one hour.

3
  • I was afraid of that....The reason i was avoiding change in batch class is...we change this duration (30 min- 1hr) many times....now have to change code everytime :( Commented Dec 5, 2017 at 11:17
  • @Dnyaneshwar You could use a custom setting to specify the minutes to wait, then change your batch class as follows: global void finish(Database.BatchableContext context) { Setting__c s = Setting__c.getOrgDefaults(); Database.scheduleBatch(this, s.Minutes_To_Next_Batch__c.intValue()); } Just a thought.
    – sfdcfox
    Commented Dec 5, 2017 at 11:25
  • yes...that can work..Thanks! If there is no way to achieve it through console custom setting would be next best thing for me... Commented Dec 5, 2017 at 12:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .