function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Anil KamisettyAnil Kamisetty 

Build the Cron Expression to run a Job every 30 Minutes

My requirement is to schedule a Job every 30 minutes. I can do this using two CRON Expresssions (as given below), but I want to see if we can do this in one expression ? Advantage of having one single job is that "if the job take more than 30 minutes to process, second job wont fire". By having two different expressions, they can be running together.

String cronStr1 = '0 00 * * * ?';
String cronStr2 = '0 30 * * * ?';
Anil KamisettyAnil Kamisetty
The below expression throws up an exception. 
String cro ='0 0/30 * * * ?';

System.StringException: Seconds and minutes must be specified as integers: 0 0/30 * * * ?
Maharajan CMaharajan C
Hi Anil,

String cronStr = '0 0,30 * * * *';

OR

String cronStr = '0 30 * * * ?';

Reference Links:
https://webkul.com/blog/cron-expression-for-scheduling-jobs-in-salesforce/
http://www.cloudforce4u.com/2013/09/batch-apex-scheduling-in-apex-batch.html
http://sfdcsrini.blogspot.com/2014/06/how-to-execute-batch-apex-class-for.html

Note:  If the above things are not works then we must have to go with the two CRON because i think schedule your batch for every 30 min '0 30 * * * ?'. then It means it will run every hours 30th minutes not for 30mins interval.

Can you please Let me know if it works or not!!!

If it helps don't forget to mark this as a best answer!!!

Thanks,
​Raj
Anil KamisettyAnil Kamisetty
Seconds, Minutes and Hours accept just the numeric values (range 0-59), nothing else. No special characters seem to be allowed, Tried Slash, Comma etc in the STring expression, get the same error.

System.StringException: Seconds and minutes must be specified as integers

And String cronStr = '0 30 * * * ?';runs the job ever hour by at 30 minute time (i.e. 1:30, 2:30, 3:30, 4:30 etc). Creating two separate expressions seems to be the way, but want to see if anyone has found any other way.
Alain CabonAlain Cabon
Until 2011, every 30 minutes was possible. https://developer.salesforce.com/forums/?id=906F00000008zElIAI

RecurringScheduleJobhttps://developer.salesforce.com/forums/?id=906F00000008yFvIAI
Doesn't exist anymore since 2013 perhaps.

http://mukeshkumararchitecture.blogspot.fr/2017/05/salesforce-scheduling-schedule-job.html
Recent post (2017) but wrong example because RecurringScheduleJob has been deprecated (nothing in Apex documentation).

Minutes: Values: 0–59  Special Characters: None   (I missed that part and that was possible in the past, many examples with 0/30 or 0,30)
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_scheduler.htm

The simple workaround is two schedules now as you have done.
Anil KamisettyAnil Kamisetty
It makes sense why there were so many posts with that cron expression, feature did exist in salesforce prior 2011 not anymore. Will see if someone comes up with an answer, if not "Two schedules might be the way to go".

String cronStr1 = '0 00 * * * ?';
String cronStr2 = '0 30 * * * ?';
PreeSFDCDevPreeSFDCDev
Hi Anil,
Did you mean to run the same job twice with these 2 cron expression? If we schedule the Job with one say (String cronStr1 = '0 00 * * * ?';) and trying to schedule with 2nd  its saying job is already scheduled for execution. How did you scheduled it twice..can u pls mention here..it will help
Abhishek Saha 20Abhishek Saha 20
Hi PreeSFDCDev,

I think you might have used same job name for both the schedules. Please use different job names for each schedule. Hope it will solve the issue.

Thanks.
Abhishek
Selvaganesh Ilango 6Selvaganesh Ilango 6
Hello,

I know this is a very old post, But recently I came across a simple tool that helps in generating the code for scheduling automatically based on the frequency you select. Please take a look.

http://radix2.tech/tools/sfdc-batch/

Thanks
Selva
Suraj Tripathi 47Suraj Tripathi 47
Hi Anil,

Cron Expression to run a Job every 30 Minutes is given below
    cron expression  =  */30 * * * *

If you find your Solution then mark this as the best answer.

Thank you!
Regards,
Suraj Tripathi