function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Abhilasha_SinghAbhilasha_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?
Juraj CiljakJuraj Ciljak
Hi :),
scheduled job is in sObject called CronTrigger, CronJobDetail 

Thanks
Juraj
Abhishek BansalAbhishek Bansal
Hi,

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, 
Smriti Kumari (Shumpy)Smriti Kumari (Shumpy)
Hi @Abhilasha,

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