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

I have finally reproduced the bug about “System.CalloutException: You have uncommitted work pending. Please commit or rollback before calling out ” error being raised when it should not be raised. It happens when there is a thrown and caught mixed DML Exception in the setup transaction inside a Queueable job, and a callout from queueable or batchable in the test transaction (but not in future method).

Code of dummy batchable class b can be located here: https://gist.github.com/bdovhan/76326745c347dde00717c0318e3bc15b

Code of Apex Test Class TRB reproducing the CalloutException bug referencing class b in one test method can be found here

In this class, there are three apex test methods. Methods testB and testQ, which make callout from Queueable or Batchable, fail, while method testF, which makes callout from Future method, doesn’t fail.

I have also created a repository which contains both apex classes and setup scripts to create a scratch org and push the script to the scratch org.

Currently working with Salesforce support to identify this as an issue and retrieve from them acknowledge of this issue.

 

 

 

This entry was posted in Bugs, platform-bug, salesforce. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s