You need to sign in to do that
Don't have an account?
suhas ghule 3
StartTime and EndTime in Cron Expression
I have a cron expression which will schedule an apex class to run on every SUNDAY
The cron Expression for that is - 0 0 0 ? * SUN *
But i want to include a StartDate and EndDate to that cron expression.
Suppose the StartDate(dd/mm/yyyy) - 12/9/2014, EndDate- 26/9/2014
The cron should only run on sundays between these two dates
Any ideas on how to do that??
The cron Expression for that is - 0 0 0 ? * SUN *
But i want to include a StartDate and EndDate to that cron expression.
Suppose the StartDate(dd/mm/yyyy) - 12/9/2014, EndDate- 26/9/2014
The cron should only run on sundays between these two dates
Any ideas on how to do that??
You can do this by writing apex class which implements schedulable interface.
You can schedule that apex class on weekly or monthly basis, also you can specify start and end date.
you can refer below links:
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_scheduler.htm
http://www.salesforce.com/us/developer/docs/apex_workbook/Content/apex_scheduling_1.htm
https://help.salesforce.com/HTViewHelpDoc?id=code_schedule_batch_apex.htm&language=en_US
If this solves your problem, kindly mark it as the best answer.
Thanks,
Vatsal
Let me rephrase my problem-
I'm scheduling my class using System.Schedule('blah blah', CRON_EXP,className);
CRON_EXP== '0 0 0 ? * SUN *' --> what this does is schedule the class on every sunday irrespective of the StartDate and EndDate.
for eg. Today's Date--> 9/10/2014
StartDate--> 9/15/2014
EndDate--> 9/23/2014
So, according to my StartDate & EndDate, the next fire time should be 9/21/2014. But here the nextFireTime is 9/14/2014.
How to get around with this problem??
you have to create Batch class which implements schedulable interface, perform all your task inside batch class.
After saving Batch class to go to setup > Develop > Apex Classes
There is a Button called Schedule Apex click on this and u'll get solution.
Thanks,
Vatsal
In Order to Schedule a class from apex class use the following syntax
here is a small Example where in am scheduling an apex class
and try to implement the logic ,which runs as per your desired conditions ..
Hope this helps you
Cheers