We have an Apex class that automatically schedule a Job to be run 10 min after the request is done. In some cases, this job doesn't run at all and since we cannot schedule another job (business requirement) we wait at least 3 hours to see if the job is executed.

After that time, we want to abort the job.

In order to know if a job is scheduled we are using the following SOQL:

List<AsyncApexJob> jobs = new List<AsyncApexJob>(
            [SELECT Id, Status, CreatedDate FROM AsyncApexJob WHERE ApexClass.Name = 'ConnectUpdateBatch' AND Status NOT IN ('Aborted', 'Completed', 'Failed')]

Using the Created Date, we know if the job is waiting for execution for more that 3 hours

Now our question is: how we can abort the job using Apex during the same verification process?


1 Answer 1


You need to query for CronTrigger and match by CreatedDate.

Also, if you the label you pass to System.schedule method, you can filter out by this label using CronJobDetail.Name = :label and CronJobDetail.JobType = 7

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .