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?

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.

  • 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 :( – Dnyaneshwar Dec 5 '17 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 Dec 5 '17 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... – Dnyaneshwar Dec 5 '17 at 12:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.