MIXED_DML_OPERATION: meaning and how to fix it
Quick answer
MIXED_DML_OPERATION: One transaction changed both a setup object (such as User, Group or PermissionSetAssignment) and a non-setup object (such as Account). Salesforce limits this mix. Start with: Move one of the DML operations to a separate transaction, such as a Queueable or @future method.
Typical message: MIXED_DML_OPERATION, DML operation on setup object is not permitted after you have updated a non-setup object (or vice versa)
Cause
One transaction changed both a setup object (such as User, Group or PermissionSetAssignment) and a non-setup object (such as Account). Salesforce limits this mix.
How to fix MIXED_DML_OPERATION
- Move one of the DML operations to a separate transaction, such as a Queueable or @future method.
- In tests, wrap the setup-object DML in System.runAs(user) { ... }.
Have a different message? Paste it into the error decoder, which matches it against 45 common Salesforce errors in your browser.
Frequently asked questions
What does MIXED_DML_OPERATION mean in Salesforce?
One transaction changed both a setup object (such as User, Group or PermissionSetAssignment) and a non-setup object (such as Account). Salesforce limits this mix.
How do I fix MIXED_DML_OPERATION?
1. Move one of the DML operations to a separate transaction, such as a Queueable or @future method. 2. In tests, wrap the setup-object DML in System.runAs(user) { ... }.
More Apex runtime errors
SFDX Talk is unofficial documentation. It is not affiliated with, endorsed by, or sponsored by Salesforce, Inc. Message text varies slightly by release and context, so confirm against the official page before relying on it.