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
roni shoreroni shore 

CRON to run batch thrice 23:00, 1:40 & 4:00

Hi Guys- can anyone help out on this, I want to schedule a batch so it runs thrice at 23:00, 1:40 & 4:00

String cronStr = '0 45 23,1,4 * * ?';

Hours I can specify comma seperated but minutes it's not taking, pls suggest
Best Answer chosen by roni shore
Khan AnasKhan Anas (Salesforce Developers) 
Hi Roni,

Greetings to you!

CRON in Apex do not support comma separated parameters in Minutes and Seconds.

You can schedule 3 instances:
public static String CRON_STR = '0 0 23 * * ?';  // For 23:00
public static String CRON_STR_2 = '0 40 1 * * ?';  // For 1:40
public static String CRON_STR_3 = '0 0 4 * * ?';   // For 4:00

Then schedule it:
System.schedule('Job 1', CRON_STR, new YourClass()); 
System.schedule('Job 2', CRON_STR_2, new YourClass());
System.schedule('Job 3', CRON_STR_3, new YourClass());

Please refer to the below link which might help you further with the above requirement.

https://salesforce.stackexchange.com/questions/83774/how-to-schedule-a-job-twice-a-day

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas