0

I don't quite know how to explain the behavior we're seeing. I have two test methods that test exactly the same thing (same inputs, same assertions). The only difference is that one schedules the job, the other executes it directly. The former is just to cover the schedulable code.

These tests have been in our org and passing for 3 years, unchanged. With Summer 22, suddenly, the schedulable test is failing with:

System.CalloutException: You have uncommitted work pending. Please commit or rollback before calling out

...but the directly executed one is passing. I found this StackExchange post from 2019 with the accepted answer being that "Scheduling the job counts as pending work for the purpose of callouts". If that's true...then fine I guess, I'll just not execute the callout and I'll make my assertions a lot simpler without actually testing the outcome of the code beyond "did it run."

But...why would this test have been passing fine until now? I can't find anything in the Summer 22 release notes that explicitly explain it. Though I do see this item regarding resource usage?

3
  • 1
    Not an answer, but I don't see a lot of value in testing that Salesforce can execute a scheduled job. You should be able (at least in unit testing) to trust that it will. What's important is testing the processing the job performs. I cannot say why it used to work nor what changed, but ditching the test that does the scheduling seems reasonable to me.
    – Phil W
    Jun 13 at 19:24
  • @PhilW Yeah, it's only for covering the Schedulable implementation, which is only one method with one line. I'm not too concerned about it, but was curious.
    – Mike
    Jun 13 at 19:26
  • Also note that Salesforce releases often have many small changes that are not mentioned in the release notes. For example, we discovered that one of our classes creates a fake ID (using the correct ID prefix) that is 2 characters too short. This used to function, but generates an exception in Summer '22.
    – Phil W
    Jun 13 at 19:26

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.