Recently (since January) we have encountered some cases when deploying new versions of our managed package.

We have had at least 2 separate instances where changing a batch or an apex class referenced in a batch breaks the async execution because the batch has an old version of the code in memory.

I was reading the question "Does Apex Engine maintains old version of apex code for Async Apex?" from 2019 and they actually say

deploying a change in logic to the batchable's execute() will pick up the changes after the deployment while the job is running

But we encountered the complete opposite scenario where some apex jobs were scheduled to run and the code base was changed, but the job that was already scheduled actually ran with the old version of the code, and the next iteration (the one scheduled/ran after the code base change) actually runs with the new code base without a problem

Is this the normal behavior with async apex now? Just wondering how is everyone handling this situation. Right now we have come down to abort all scheduled jobs of any scheduled apex job being modified between package versions, but it's something really hard to narrow down if a reference has been modified in a way that may break the code.

  • Are you 100% sure the package update successfully installed? Have you checked the Installed Packages list to verify installed package version?
    – Phil W
    Feb 20 at 22:25
  • You're not confusing schedulable and batchable, are you? That answer is, as far as I'm aware, still correct, but schedulable plays by different rules...
    – sfdcfox
    Feb 20 at 23:07
  • 100% sure. By schedule, I was referring that the batch is already scheduled for execution before the package upgrade, and it runs after the package is installed. So let's say it's scheduled at 8 am to run at 10 pm, then at 10 am the package is upgraded. When it runs at 10 pm the batch runs with the code base prior to the upgrade that's already installed (and sometimes there are breaking changes).
    – Jose
    Feb 21 at 20:06


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.