3

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?

1

Good news, this is possible. As discussed in How can I query the class which the schedule job will call the CronTrigger and 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 destructiveChanges.xml

<?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 08e)

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'
| improve this answer | |
0

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 :

  • WAITING—The job is waiting for execution.
  • ACQUIRED—The job has been picked up by the system and is about to execute.
  • EXECUTING—The job is executing.
  • COMPLETE—The trigger has fired and is not scheduled to fire again.
  • ERROR—The trigger definition has an error.
  • DELETED—The job has been deleted.
  • PAUSED—A job can have this state during patch and major releases. After the release has finished, the job state is automatically set to WAITING or another state.
  • BLOCKED—Execution of a second instance of the job is attempted while one instance is running. This state lasts until the first job instance is completed. PAUSED_BLOCKED—A job has this state due to a release occurring. When the release has finished and no other instance of the job is running, the job’s status is set to another state.
| improve this answer | |
  • 2
    Thanks.But i want to know the job name for perticular apexclass. Like I have a Apex class name MyControllerClass and it sheduled. But how cant i find Scheduled job for the above class. – ajay bagdad Nov 19 '15 at 3:54
  • how many result you see with thst query ? – Himanshu Nov 19 '15 at 4:08
  • I can see 67 results – ajay bagdad Nov 19 '15 at 4:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.