I have one apex schedulable class. I am trying trying to search class in All Scheduled Jobs,but I don't know the name of job for that particular apex class.
How should I find the job name for that scheduled class?
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It only takes a minute to sign up.Sign up to join this community
Good news, this is possible. As discussed in How can I query the class which the schedule job will call the
CronJobDetail tables which underly schedule jobs have a gaping hole in that they don't include details about the associated apex class id (at least that they expose). See the these two ideas to vote it up.
In some cases if you go to setup->monitor->jobs->scheduled jobs, and you'll see a list of all scheduled jobs. For apex classes that were scheduled through the 'Schedule Apex' button in setup->develop->apex classes, you'll see a 'Manage' link next to the job. Click that and you'll see the class name associated with that job.
However, it turns out the metadata api is kind enough to return the id of the
CronTrigger records associated with an apex class if you try and delete it.
So let's say your class is
MySchedulableClass you would have the following
<?xml version="1.0" encoding="UTF-8"?> <Package xmlns="http://soap.sforce.com/2006/04/metadata"> <types> <members>MySchedulableClass</members> <name>ApexClass</name> </types> <version>41.0</version> </Package>
If you do a test deployment, you'll get an error like the following which includes the crontrigger ids (they start with
BUILD FAILED /Users/yourname/ant/sfse/build.xml:95: The following error occurred while executing this line: /Users/yourname/ant/sfse/build.xml:55: *********** DEPLOYMENT FAILED *********** Request ID: 0AfXXXXXXXXXXXXXXX All Component Failures: 1. classes/MySchedulableClass.cls -- Error: This apex class is referenced elsewhere in salesforce.com. Remove the usage and try again. : Scheduled Jobs - 08eXXXXXXXXXXXX. This Schedulable class is in use. : Apex Class. *********** DEPLOYMENT FAILED ***********
Once you have those ids you can then query the related job names
SELECT CronJobDetail.Name FROM CronTrigger WHERE Id = '08eXXXXXXXXXXXX'
You can run following query to find out the job name
SELECT CronJobDetailId,cronjobdetail.Name,EndTime,Id,LastModifiedById, NextFireTime,OwnerId,PreviousFireTime,StartTime,State FROM CronTrigger where state='WAITING' and cronjobdetail.JOBTYPE='7'
Possible STATE values are which you can use to filter results are :