[SalesForce] view Apex job details

There are some scheduled Apex jobs in Setup -> Environments -> Jobs -> Scheduled Jobs that I'd like to reassign to a different user so that I can deactivate the one they are currently assigned to (limited licenses…). However it seems the only way to do this is to delete and re-create these jobs. My question is, where can I see the information on these jobs so I can accurately recreate them?

Thanks!

Best Answer

You can get this information by querying the CronTrigger and CronJobDetail objects:

SELECT CronJobDetail.Name, CronExpression, OwnerId 
FROM CronTrigger 
WHERE CronJobDetail.JobType = '7'

JobType 7 is Scheduled Apex.

The CronExpression is the critical Cron timing string that you can pass to System.schedule(), which allows for types of schedules that are not supported in the user-interface scheduler; that will let you rebuild the jobs on the same schedule as you expect.

The easiest place I am aware of that you can see the Apex class name, frustratingly, is the job's detail page under Scheduled Jobs in Setup:

Screen shot of Setup UI

You can find Apex class names from the AsyncApexJob object, which represents the queued run of the scheduled job, but I'm not aware of any way other than visual inspection to correlate the AsyncApexJob back to the parent CronTrigger (its ParentJobId is blank). Regardless, you can query

SELECT ApexClass.Name FROM AsyncApexJob WHERE JobType = 'ScheduledApex'

You'll be able to view the actual class code only if it's not part of a managed package.

You can schedule a job programmatically by opening Anonymous Apex in the Developer Console and entering

System.schedule('My Job Name', '0 0 * * * ?', new MySchedulableClass());

The second argument is your CronExpression from the CronTrigger query.