1

I recently created a scheduled Apex job in a sandbox, then later tried to abort it and was unable to because I didn't have the CronTrigger ID and couldn't find it. I found several questions on stackexchange about similar issues, tried running queries in the query editor in dev console to get the CronTrigger ID, but was not able to get it to work. Eventually the only way I was able to get the scheduled job to stop running was to run a script that cancelled ALL scheduled jobs in the sandbox. Which was not a big deal because it was in sandbox.

However, now I'm ready to deploy this to production and want to make sure I understand how to cancel a scheduled job once I start it. I can't schedule it through the UI because (as far as I understand) there's no way to schedule an hourly job from Setup => Apex Classes => Schedule Apex -- only daily / weekly / monthly jobs can be scheduled that way.

So first question: Is there any way to schedule an hourly job in the UI?

If not, then What is the right way to schedule a job from the dev console so that I can abort it later when I need to?

The way I did it in sandbox was open Execute Anonymous Window and run System.schedule( ... ). This worked to start the job but then for some reason I was never able to find the CronTrigger ID to abort it. Is there a way to do this better from the start so I can save the CronTrigger ID as soon as the scheduler is launched so I don't have to search for it later?

3

Is there any way to schedule an hourly job in the UI?

No.

What is the right way to schedule a job from the dev console so that I can abort it later when I need to?

You can still view it in scheduled jobs in Setup, and abort it from there. You don't need the Job ID.

Alternatively, you can do this in an execute anonymous script:

CronTrigger ct = [SELECT Id FROM CronTrigger WHERE CronJobDetail.Name='NameofJob' and 
  State = 'Waiting'];
System.abortJob(ct.Id);
  • thanks, i didn't realize i could cancel directly from Setup without an ID, wish i had figured that out before i nuked my entire sandbox :) – Sarah Mar 22 at 16:11

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.