1

I have seen many posts about finding out name of the apex class associated with a scheduled job. However, i have an opposite need.

I am updating a scheduled class, that was scheduled to run at a certain frequency every week. It was scheduled several years ago, so at this stage, nobody remembers the Job name.

Before i can deploy my edited class, i need to de-active the scheduled job associated with the class, otherwise deploy will fail.

So my question is, if i have a schedulable apex class xyz.cls. Is there a way to find out IF it is scheduled to run already? If yes, is there a way to find out what's the job name and whats the schedule frequency?

  • 2
    Are you aware there is a setting that will allow you to deploy regardless of whether a job is running or is scheduled? – Sebastian Kessel Jul 9 at 22:10
3

There are two things for you here:

  1. Go to Setup -> Deployment Settings and check the box labeled "Allow deployments of components when corresponding Apex jobs are pending or in progress."

Note, as the label itself explains, enabling this option may cause Apex jobs to fail.

  1. If, for whatever reason, item 1 is not good enough, you can query the AsyncApexJob object. There property ApexClassId that will give you the apex class.

For example, you can do:

SELECT <yourFields> 
FROM AsyncApexJob
WHERE ApexClass.Name = <Your class Here>
| improve this answer | |
  • 1
    Unfortunately this doesn't help you know the name of the scheduled job, of course, and there doesn't appear to be a way to attack it from the other end using CronTrigger and CronJobDetail either. However, using the setting should be good enough. – Phil W Jul 9 at 22:21
  • Help me out here, because I am second-guessing myself. Can you do System.abortJob(xxx) with the ID out of that object? – Sebastian Kessel Jul 9 at 22:22
  • Nevermind, you can. So, while you don't get the Job Name, you can abort it anyway using apex. You still can't unschedule it, though. Reference: developer.salesforce.com/docs/atlas.en-us.apexcode.meta/… – Sebastian Kessel Jul 9 at 22:23
  • @SebastianKessel Yes I am aware of that setting you mentioned. And we do have it checked, so it shouldn't be problem. But i found out about that setting only few days ago, and before that, i was trying to find the job name. Even though, its not needed anymore (due to that setting being checked), i was curious about finding job name from class name. So looks like there is no good way for it. But thank you for your responses. Confirming my understanding about that deployment setting itself was great help. – user2957592 Jul 10 at 5:34

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.