This must have its root cause in a Winter '18 change/bug as this worked before for years.

When uploading a big (takes a while to upload) managed packaged that contains Apex Tooling API - REST edition and Apex Wrapper Salesforce Metadata API the upload fails with:

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

...in many and not always the same tests:

enter image description here

(Note: Also created issue at https://github.com/financialforcedev/apex-mdapi/issues/189)


It looks like a new salesforce bug that happend to me after W18 rollout, too. Thanks to @BritishBoyinDC, there is a workaround which is working for me:

Salesforce Packaging Bug with Lightning Components? (Warning: very strange!)

The gist of it is: Modify the test-class so that the code that invokes the callouts is wrapped like this

    // Invoke code that makes callout
Test.Stop Test()

The coverage will not go down but stay exactly as it was. My MetadataService.cls is still 100% covered and all package uploads are succeeding again as before W18.

  • It worked. @BritishBoyinDC and you saved my weekend. I owe you both a beer. Oct 28 '17 at 20:02

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.