5

I have a job and I have to schedule this Job twice a day.

Currently it is running at 12 PM ET and 1 PM ET. So my Cron String looks like this.

public static String CRON_STR = '0 0 12,13 ? * MON-FRI *';

But instead of 1 hour, I want it to run at 12:01 PM ET and 12:15 PM ET.

Please advise.

6

You need to schedule 2 instances:

public static String CRON_STR = '0 1 12 ? * MON-FRI *';
public static String CRON_STR_2 = '0 15 12 ? * MON-FRI *';

Then:

System.schedule('Job 1', CRON_STR, new YourClass());
System.schedule('Job 2', CRON_STR_2, new YourClass());
  • 2
    Can't we construct a single cron string ?? – SFDC Geek Jul 17 '15 at 5:24
  • 1
    Unfortunately not, you can only do that with hours and greater units. When it comes down to minutes and seconds, multiple jobs are required. – Boris Bachovski Jul 17 '15 at 5:34
  • 3
    This definitely works but - I think we can achieve it in single CRON and schedule, check my answer below. thanks! – Amit Bangad Jul 17 '15 at 7:20
3

EDIT

Earlier I thought that this can be done using a single Cron expression.

public static String CRON_STR = '0 1,15 12 ? * MON-FRI *';

If you want to validate, please enter this cron at http://www.cronmaker.com/ and check the future runs.

enter image description here

BUT

Apparently CRON in Apex do not support comma separated parameters in Minutes and Seconds. So we are stuck with 2 options :

  1. Either scheduling 2 jobs like Accepted Answer, or
  2. Getting creative by scheduling a following job in the Finish() method of your batch class to ensure optimum resource utilization.
  • 1
    But I am getting below Error: System.StringException: Seconds and minutes must be specified as integers: 0 1,15 12 ? * MON-FRI * – SFDC Geek Jul 17 '15 at 9:07
  • 1
    I did not try scheduling, I just tried genering CRON. Let me check – Amit Bangad Jul 17 '15 at 9:09
  • 1
    Corrected my Answer! – Amit Bangad Jul 17 '15 at 9:26

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.