+ Start a Discussion
Utkarsh Ugale 8Utkarsh Ugale 8 

How to retrieve Apex Class name from CronTrigger ?

I am working on writing a service which is expected to monitor Scheduled batch jobs. I am querying CronTrigger to get list of all scheduled classes but could not find a direct way to find out which ApexClass is scheduled. 

Is there a way in recent releases to find out which apex class is scheduled in particular CronTrigger record in Apex ?
Ravi Dutt SharmaRavi Dutt Sharma
Hi Utraksh,

Try using below SOQL:
 
select ApexClass.Name, ApexClass.Namespaceprefix, Id, JobItemsProcessed, JobType, Status, NumberOfErrors, MethodName from AsyncApexJob where JobType in ('BatchApexWorker','ScheduledApex')

 
Utkarsh Ugale 8Utkarsh Ugale 8
@Ravi...this query will not work as I want to find an ApexClass name from CronTrigger. Record in AsyncApexJob gets created when scheduled apex is run on given time.
Utkarsh Ugale 8Utkarsh Ugale 8
@niraj CronJobDetail.Name does not give apex class name but name (label) of CronJob record which was entered by user while scheduling an apex. While Scheduling an apex class via 'Schedule Apex' option in setup - > classes, Salesforce asks label & Apex class for scheduling. CronJobDetail.Name returns that label string but not Apex class which was selected.
Raj VakatiRaj Vakati
No direct way with SOQL .. 

You can go to apex scehduerl jobs from the monitering section and you can able to fine the apex class that are using in jobs ..

https://help.salesforce.com/articleView?id=code_apex_job.htm&type=5