[SalesForce] Get the scheduled Job name using Apex class name

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?

Best Answer

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>
Related Topic