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:
This article explains the options available to edit the affected Apex classes in these scenarios.
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.
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.
First, you need to determine whether the issue is occurring when editing an Apex class or when performing a deployment in that sandbox.
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]));
}
}
000384960

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.