[SalesForce] How to set the Start and End Date in the cron expression

I would like to schedule the apex classes through apex code. I am able to set the cron expression for the frequencies, but I am unable to set the start and end DATE(i.e when the scheduling may start and End) through Apex Code.

Is there any way to define the cron expression to achieve this. Thanks in advance.

Best Answer

You are allowed to set the day of the month, month and year in the cron expression, this combined with the "-" (hyphen) character you can specify a range of your start date and end date.

An example would be the following which will run from 7-July-2013 to 15-July-2013 everyday at 1 AM

0 0 1 7-15 7 2013

For more information see this section of the Apex Scheduler documentation

Related Topic