How to resolve the error - This schedulable class has jobs pending or in progress at line 11 column 8?

1.0K    Asked by DipikaAgarwal in Salesforce , Asked on May 4, 2023

When I edit and try to save an Apex class, I get the following message: Compile Error: This schedulable class has jobs pending or in progress at line 11 column 

How can I fix this?

Answered by elonjigar

To resolve the error - This schedulable class has jobs pending or in progress at line 11 column 8 - As per Salesforce help article https://help.salesforce.com/s/articleView?id=000323577&type=1 this can also happen "When editing a class being called by a class that is called in the execute() method, in other words, a dependent class." which makes it a lot more difficult to find out the dependent schedulable class / scheduled job. However, metadata APIbased deployment https://developer.salesforce.com/docs/atlas.en-us.220.0.api_meta.meta/api_meta/file_based_zip_file.htm is able to work around this problem and make changes to the class.



Your Answer

Answer (1)

The error message "This schedulable class has jobs pending or in progress at line 11 column 8" in Salesforce indicates that you are trying to update or delete a schedulable class while it has scheduled jobs that are either pending or currently in progress. Salesforce does not allow modifications to schedulable classes in such cases.

To resolve this issue, follow these steps:

1. Identify Scheduled Jobs

You need to identify the scheduled jobs associated with the schedulable class. You can do this through the Salesforce user interface or using Salesforce's Developer Console.

Using Salesforce User Interface

Navigate to Setup: Go to Setup in Salesforce.

Search for Scheduled Jobs: In the Quick Find box, type "Scheduled Jobs" and select it.

Locate Jobs: Look for the jobs that are using the schedulable class you want to modify.

Using Developer Console

Open Developer Console: In Salesforce, click on your avatar in the upper right corner and select "Developer Console."

Execute Anonymous Apex: Press Ctrl+E to open the Execute Anonymous window, and run the following code to list scheduled jobs:

  List cronTriggers = [SELECT Id, CronExpression, State, TimesTriggered, NextFireTime FROM CronTrigger WHERE CronJobDetail.Name = 'YourSchedulableClassName'];for (CronTrigger ct : cronTriggers) {    System.debug('Scheduled Job: ' + ct);}

Replace 'YourSchedulableClassName' with the actual name of your schedulable class.

2. Abort Scheduled Jobs

Once you have identified the scheduled jobs, you need to abort them. This can also be done through the Salesforce user interface or using Apex code.

Using Salesforce User Interface

Locate and Delete Jobs: In the Scheduled Jobs page, find the jobs related to your schedulable class and click "Delete" next to each job to abort them.

Using Developer Console

Abort Jobs Using Apex: Run the following code in the Execute Anonymous window to abort the jobs:

  List cronTriggers = [SELECT Id FROM CronTrigger WHERE CronJobDetail.Name = 'YourSchedulableClassName'];for (CronTrigger ct : cronTriggers) {    System.abortJob(ct.Id);}

Replace 'YourSchedulableClassName' with the actual name of your schedulable class.

3. Modify the Schedulable Class

After aborting all scheduled jobs, you should be able to modify your schedulable class without encountering the error.

Edit the Class: Go to the Apex Classes page, locate your schedulable class, and make the necessary modifications.

Save the Changes: Save the class after making your changes.

4. Reschedule the Jobs (If Needed)

If the scheduled jobs are still required, you can reschedule them after modifying the class.

Using Salesforce User Interface

Schedule Apex Job: Navigate to Setup > Apex Classes > Schedule Apex and set up your schedulable class again.

Using Apex Code

Schedule Job Using Apex: Run the following code to schedule the job:

  YourSchedulableClassName yourClass = new YourSchedulableClassName();String schedule = '0 0 12 * * ?'; // Example cron expression for daily at noonSystem.schedule('Scheduled Job Name', schedule, yourClass);

Replace YourSchedulableClassName with the name of your class and adjust the cron expression as needed.

By following these steps, you should be able to resolve the error and successfully modify your schedulable class.

4 Months

Interviews

Parent Categories