+ Start a Discussion

CronTrigger StartTime and EndTime


If you look at the CronTrigger object description there are fields called StartTime and EndTime:  http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_crontrigger.htm


It appears these fields are NOT writable.


 Using System.Schedule (http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_scheduler.htm) method does not accept start time or end time for a cron job.  This means any job scheduled through System.Schedule has StartTime as the current date/time and EndTime is null.


How does one set CronTrigger StartTime and EndTime fields for jobs scheduled using System.Schedule?





String sch = '0 0 1 * * ?'; <== This will start the Job at 1 AM everyday.
String jobID = system.schedule('Merge Job', sch, m);



You have to look at this section: to know about the time pattern


Using the System.Schedule Method




But how do you use system.schedule to only run the job from 10/22/2013 to 10/22/2014 ?

Through the schedule apex screen in the salesforce setup menu it is possible to set starttime and endtime.  It appears system.schedule is lacking support for specifying CronTrigger.StartTime and CronTrigger.EndTime.


Can salesforce product management please confirm?

kevin lamkevin lam

Use 2013-2014 in the parameter for the year.


There is no way to modify a Schedule job right now even in setup page. 


The only way to modify the Job is that you have to delete the existing one and then reschedule it with other expression.


You can specify the range of years you want to schedule.


"0 0 1 3 */3 ? 2013-2015" <<-- this will run the job at 1 AM third day of every 3 months from 2013 to 2015.


Hope this help


The issue I have is that the fields CronTrigger.StartTime and CronTrigger.EndTime are not exposed via System.schedule.  The fields cannot be updated using APEX / SOQL either.


These fields can be specified when sheduling a job in the salesforce UI.



I added a comment to the existing idea: https://success.salesforce.com/ideaView?id=08730000000g9BmAAI