1

Is it possible to set the StartTime and EndTime fields of a CronTrigger object ?

I'm not able to set this fields in Apex code, I have the error below :

Field StartTime is not writeable

I know I can do it directly in CRON expression but only for simple expression.

For example, if I want to schedule a job every Monday at 2:00PM between 23th March 2015 and 12th January 2016, how can I do it with a CRON expression ?

When I schedule an APEX class in Salesforce GUI, I can choose the startTime and EndTime, so I think it's possible !

Any ideas ?

3

Lets say you want to schedule a class which run from 20-August-2015 to 30-August-2015 daily at 7 AM. Cron expression would be:

0 0 7 20-30 8 2015

Lets say you want to schedule a class which run from 20-August-2015 to 20-August-2016 daily at 7 AM. Cron expression would be:

0 0 7 20 8 2015-2016

Cron for running a batch every Monday at 2:00 PM is

 0 0 14 ? * 2

You can not write directly to fields. You will have to reschedule the class and delete old schedule.

2
  • Ok, thanks. But in your examples, you have dates in the same month or in the same year. In my example, I would like to do every Monday at 2:00PM between 23th March 2015 and 12th January 2016. Is there possible to do this type of complex interval with a CRON expression ? – SF_user Aug 20 '15 at 7:38
  • @SF_user You will need to create two schedules. one schedule will run from 23 march 2015 to Dec 2015 & 2nd schedule will run for 1st January 2016 to 12th January. Cron for running a batch every Monday at 2:00 PM is 0 0 14 ? * 2 – Ashwani Aug 20 '15 at 8:00

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.