1

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.

2

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

0

This totally depends on the requirement if it is worth the investment of time. If I were you I would schedule the job using apex scheduler and do a one time change from the interface. Once the job is scheduled you can click on manage next to the job and this being a one time change you can do it manually by just changing the start and end date, unless there is a special requirement that you need to stop and start the scheduled job on specific days.Please clarify why you would want to look for a programmatic approach.

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.