This post is a part of the daily blog series
Day #20 – Deploy while running Scheduled Jobs
While deploying an apex class via change sets or Force.com IDE, you sometimes receive one of these error messages –
“Schedulable class has jobs pending or in progress”
” This Apex class has batch or future jobs pending or in progress!”
When this error occurs, you cannot continue the deployment process. The error is expected and it occurs because the class is scheduled to run at a later time, and editing it or its dependencies either manually or via a deployment could result in the class having a behavior different from the one it had when it was originally scheduled. Fair enough! By default, changes to Apex code that have Apex jobs pending or in progress can’t be deployed.
There are 2 options to get around this deployment error.
- Abort Scheduled Jobs, Deploy, Schedule Jobs
Go to Setup–> Monitoring–> Scheduled Jobs. Abort (delete) the jobs that are related to the apex class you are deploying. Now try deploying the change set. It will be successful. Then schedule the apex class again.
Note: For you to go with this option, you need to know “how and when” to schedule the apex class. Before deleting the scheduled job, make sure you are aware of the schedule timings and the classes to schedule.
- Modify Deployment Settings
Go to Setup –> Deploy –> Deployment Settings. You can enable “Allow deployments of components when corresponding Apex jobs are pending or in progress” under Deployment Settings. This option lets you deploy components that are referenced by Apex jobs.
Note: Choose this option, if you are sure that the next scheduled run of the job is not during the deployment of change set i.e., the scheduled run is after the deployment.
After deployment, for the next scheduled run to automatically take the newest apex class code that is now deployed, you need to compile all classes by clicking on ‘Compile All Classes’ in Setup –> Apex Classes