How to Query All the batch classes in your Salesforce Instance using APEX
You can use the following scripts to know the batch classes in your Salesforce instance.
ListasyncApexJobList = [select ApexClassId, Id, JobItemsProcessed, JobType, Status, NumberOfErrors, MethodName from AsyncApexJob where JobType in ('BatchApexWorker','BatchApex')]; List idList = new List (); for(AsyncApexJob eachRecord:asyncApexJobList){ idList.add(eachRecord.ApexClassId); } List apexClassList = [Select Name from ApexClass where Id IN:idList]; for(ApexClass eachApexClass : apexClassList){ System.debug(eachApexClass.Name); }
Additionally, You can use above to get all schedulable and other classes by adding the JobType filter. The possible values for JobType are:
- Future
- SharingRecalculation
- ScheduledApex
- BatchApex
- BatchApexWorker
- TestRequest
- TestWorker
- ApexToken
- Queueable
Also, you can use the above script to find the status of the job as well by adding a filter on AsyncApexJob.Type. The possible values are:
- Holding
- Queued
- Preparing
- Processing
- Aborted
- Completed
- Failed
Please refer below URL for details regarding AsyncApexJob.
https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_asyncapexjob.htm
Comments
Post a Comment