[SalesForce] What can cause “System.CalloutException: You have uncommitted work pending. Please commit or rollback before calling out”

What else, other than insert/update/upsert/delete, can cause "System.CalloutException: You have uncommitted work pending. Please commit or rollback before calling out"? I've search the debug logs multiple times, and there absolutely is not a DML statement executed between the startTest and the failing callout.

Are there any other commands, or perhaps another callout (even though it's only an inquiry), that can cause this? Does anyone know how to get around this problem?

Best Answer

Here is a list of the operations that could possibly count as a DML when executed before a callout:

  • Database methods
    • convertLead
    • delete
    • deleteAsync
    • deleteImmediate
    • emptyRecycleBin
    • executeBatch
    • insert
    • insertAsync
    • insertImmediate
    • merge
    • rollback
    • setSavepoint
    • undelete
    • update
    • updateAsync
    • updateImmediate
    • upsert
  • System methods
    • abortJob
    • enqueueJob
    • movePassword
    • process
    • purgeOldAsyncJobs
    • resetPassword
    • schedule
    • scheduleBatch
    • setPassword
    • submit
  • Messaging methods
    • reserveMassEmailCapacity

Special Case - During tests when object has an email alert

If using API v38 or earlier during test methods when an email alert is set on the object will also produce this error

https://success.salesforce.com/issues_view?id=a1p300000008XHBAA2