0

I was working with Scheduled apex and it seems quite simple that you define a cron expression and then simply schedule it and later on you can monitor the progress of your job under scheduled jobs and Apex jobs.

However I noticed a few things and would like to share here and if possible get answers from this incredible community.

  1. Zombie Jobs: Salesforce create these zombie jobs which do not contain a parent crontrigger object. I mean these jobs are not appearing under crontrigger but when you query AsyncApexJob Object you'll find them here but you cannot delete them without the parent crontrigger id.

  2. Null NextScheduledTime: When an apex job gets completed sucessfully salesforce sets the Next Scheduled time to null and you have to manually abort the job.That is my understanding. Wouldn't it be great if after execution the jobs gets terminated automatically?

1

Zombie Jobs: Salesforce create these zombie jobs which do not contain a parent crontrigger object. I mean these jobs are not appearing under crontrigger but when you query AsyncApexJob Object you'll find them here but you cannot delete them without the parent crontrigger id.

This should only happen in Sandboxes, and can be fixed by Support. If this happens in production, make sure you contact Support anyways, this is not normal behavior. Also, this solution may also work (running the script as v31.0 API using the AsyncApexJob Id).

Null NextScheduledTime: When an apex job gets completed sucessfully salesforce sets the Next Scheduled time to null and you have to manually abort the job.That is my understanding. Wouldn't it be great if after execution the jobs gets terminated automatically?

This is a feature. It allows to you check and make sure your job actually did run. Such jobs don't count against the 100 job limit. Also, you can use the System.purgeOldAsyncJobs method to delete the old jobs that have completed. You could even schedule this to run nightly or weekly to keep your list trimmed down automatically.

1
  • thanks @sfdcfox. You are a big help – Usama Ahsan Jul 13 '20 at 17:02

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.