I have scheduled the job with particular time interval through apex using 'System.schedule()' method. Now i want to identify, what is the time interval of scheduled job?
For example: if i scheduled jobs with '15 minute' time interval. -> Here, 4 jobs will scheduled with 15 min time interval. then how can i find the time interval of two different scheduled job.
I want to use this time interval in another task. Please help me.
Thank in advance.
I have used this 'CronTrigger' object already.
- If there are more than one jobs are scheduled then by using 'StartTime' of tow different jobs, we can identify the time interval of scheduled job.
For example, if jobs scheduled for '15 min' time interval then there are 4 jobs are scheduled. like,
String sch15 = '0 15 * * * ?'; System.schedule(' Sync 15 Min', sch15, c); String sch30 = '0 30 * * * ?'; System.schedule(' Sync 30 Min', sch30, c); String sch45 = '0 45 * * * ?'; System.schedule(' Sync 45 Min', sch45, c); String sch00 = '0 00 * * * ?'; System.schedule(' Sync 0 Min', sch00, c);
Then by using CronTrigger object,
List<CronTrigger> listCronTrigger = [select Id, CronExpression, EndTime, NextFireTime, OwnerId, PreviousFireTime, StartTime, State, TimesTriggered, TimeZoneSidKey from CronTrigger where State = 'Waiting' or State='Running' or state ='acquired']; DateTime t1 = listCronTrigger.NextFireTime; DateTime t1 = listCronTrigger.NextFireTime; Long l1 = t1.minute(); Long l2 = t2.minute(); Long result = l2 - l1;
Here we get the time interval in 'result'.
- But if there is only one job schedule for, let say every 2 hour, then only one job scheduled.
String sch00 = '0 0 1,3,5,7,9,13,15,17,19,21,23 * * ?'; System.schedule(' Sync 2 Hour', sch00, c);
In this case i unable to find the time interval.