Loading

Error 'This Apex class has batch or future jobs pending or in progress'

Publiseringsdato: May 1, 2026
Beskrivelse

When editing an Apex class or deploying Apex code via change sets, the Salesforce UI, or the Developer Console, you might receive the following error:
'This Apex class has batch or future jobs pending or in progress'


This error occurs because the class is scheduled to run at a later time. Editing it or its dependencies — either manually or via a deployment — could cause the class to behave differently from when it was originally scheduled. The following scenarios typically trigger this error:

  1. When editing a class that implements 'Schedulable' and has been scheduled via the UI or via the System.schedule() method.
  2. When editing a class called by the execute() method of a scheduled class.
  3. When editing a class called by a class that is called in the execute() method — a dependent class.
  4. When deploying any of the above classes via change sets or other deployment methods.

This article explains the options available to edit the affected Apex classes in these scenarios.

Løsning

To resolve the Salesforce Apex error 'This Apex class has batch or future jobs pending or in progress.' This error appears when you attempt to edit or deploy an Apex class that is scheduled or has pending batch or future jobs associated with it. The resolution depends on whether the issue is occurring in Production or Sandbox.

 

Issue is occurring in Production

  1. To prevent the error from occurring navigate to Deployment Settings and enable 'Allow deployments of components when corresponding Apex jobs are pending or in progress'

 

This option lets you deploy components that are referenced by Apex jobs. More information about this feature can be found here Deployment Connections and Options,.

Note: For issues occurring when editing a class via the UI or Developer console follow instructions for sandbox sections below.

 

Issue is occurring in Sandbox

First, you need to determine whether the issue is occurring when editing an Apex class or when performing a deployment in that sandbox.

 Issue occurs when editing Apex class

  1. If you know the scheduled jobs that are related to this class or its dependent classes, you can abort the jobs manually from Setup | Jobs | Scheduled Jobs.
  2. Because the error can occur due to dependent classes, you might need to find these in order to understand where the error is coming from, or which class is actually scheduled. To view the dependent classes, you can click on the Dependencies button in the class in question, this will only show you the classes that are called from within the current class. If you need to search for the classes that call this class, you can use the Developer Console 'Search in Files' option.
  3. If you are unable to locate the scheduled jobs in question, another option is to run the below anonymous Apex code in the Developer Console to abort all the scheduled jobs in the org.

Notes:

  • Running this code will delete ALL scheduled jobs in the organization
  • You will need to reschedule all jobs manually after running this
  • If you are unsure of the impact of this, please contact your internal development team
  • If you wish to use ScheduleJob ID  instead of cronTrigger ID to abort the job using System.AbortJob()  use API version 32.0 or below 
List<CronTrigger> listCronTrigger = [select Id, CronExpression, EndTime, NextFireTime, OwnerId,
        PreviousFireTime, StartTime, State, TimesTriggered, TimeZoneSidKey from CronTrigger 
        where State = 'Waiting' or State='Running'];
        
System.debug('No of jobs: '+listCronTrigger.size());

If (listCronTrigger.size() > 0)
{
    for (Integer i = 0; i < listCronTrigger.size(); i++)
    { 
        System.abortJob(listCronTrigger[i].Id);
        System.debug('Job details ::'+String.valueOf(listCronTrigger[i]));
    }
}
 

Issue occurs during deployment

  1. You can enable 'Allow deployments of components when corresponding Apex jobs are pending or in progress. under Deployment Settings.

 

What to do if neither steps fix the issue?

If you are still receiving this error, please log a case and ask Support to follow the steps mentioned in article 000342980. By mentioning the Article Number our agents will be able to process your request more accurately.
Flere ressurser

Apex Scheduler

Knowledge-artikkelnummer

000384960

 
Laster
Salesforce Help | Article