1

Currently I'm using the System.abortJob(job.Id); method to abort the execution of already scheduled cron jobs as per the following code:

List<CronTrigger> cronjobList = [SELECT Id, CronJobDetail.Name FROM CronTrigger WHERE CronJobDetail.Name IN :cronJobNames];
        for (CronTrigger job : cronjobList) {
            System.abortJob(job.Id);
        }

I need to use DELETE query instead of invoking the System.abortJob(job.Id); method.

I need to know how to be able to delete scheduled cron jobs and which database tables I need to change?

3

Salesforce doesn't expose API to delete cron job. Until now, it allows us to abortJob.

There is an idea Ability to Modify/Delete Scheduled Apex jobs, expose CRON API posted 7 years ago, you can vote on this idea.

  • Is it possible to delete the scheduled cron jobs directly from table CronTrigger? There should be a way to delete cron jobs manually by using query. – lemdev Mar 6 at 19:33
  • @lemdev Why do you believe this is possible? Many system objects in Salesforce are read-only. – David Reed Mar 7 at 0:31
1

Today, there is a background job called "CleanupCronTriggerJob" which hard deletes these jobs which are in DELETED state and last_update > sysdate -10 (State=Deleted and are older than 10 days)

More about the process: When an Apex job (e.g. an Apex class implementing the Schedulable interface) is scheduled in Salesforce, a CronTrigger record is created to represent the scheduled information of a job. For scheduled jobs that run once off or have a specified finite run time, their State field is set to 'DELETED' on completion. Are these jobs automatically purged?

The answer is Yes and It is a background job called "CleanupCronTriggerJob"

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.