This post is a part of the daily blog series
A Tip A Day, daily dosage of learning!
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
5 Replies to “A Tip A Day #20 – Deploy while running Scheduled Jobs”
So, after deployment, the scheduled run will automatically take the newest apex class code to run. – and here you are wrong because after installing batch job it will work with old code and need to reschedule.
LikeLiked by 1 person
Thanks for pointing it out. I also found out that you need not reschedule the classes (that would dissolve the whole purpose of that checkbox), instead you can just click on “compile all classes” that would be enough to trigger the next scheduled runs to take the new code.
Thanks for that tip. Maybe in the next post you will describe the solution to the
“removal of scheduled jobs after the sandbox refresh” ?
LikeLiked by 1 person
Sure, will do! Thank you!!!