You need to sign in to do that
Don't have an account?
Abhilasha_Singh
How to get a Scheduler Apex job is Scheduled or not in Apex?
I have a Scheduler class, I want to check before running this class weather this sceduler class is already scheduled or not in my Apex class?
scheduled job is in sObject called CronTrigger, CronJobDetail
Thanks
Juraj
If you try to schedule a Batch again with the help of scheduler class than you will recieve a error as follows :
"This Apex Job name "Your Scheduler Name" is already scheduled for execution".
However you can go and check in the Scheduled Jobs that your class has been alrady scheduled or not .
Setup -> Monitoring -> Schduled Jobs
Here you will get all the classes that has been scheduled.
If you want to reschedule it than delete it from here and schedule it again
Let me know if you need more help,
You can get it from CronTrigger object query. Say for example "[SELECT Id,
CronJobDetail.Name,
CronJobDetail.Id,
State
FROM CronTrigger
where CronJobDetail.Name =:<Add filter here>
AND State !='COMPLETE']".
This will give you the scheduled jobs if any.
See : https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_crontrigger.htm
You can also check jobs in batch finish method :
AsyncApexJob apexJob = [SELECT Id, Status, NumberOfErrors, JobItemsProcessed, TotalJobItems, CreatedBy.Email
FROM AsyncApexJob WHERE Id = :BC.getJobId()];
Thanks,
Smriti