When you compare Apex test results between two execution contexts in Salesforce, the number of test failures can differ. Tests run through the Salesforce User Interface (UI), using either Run All Tests or an individual Apex test class, may show MIXED_DML_OPERATION failures. The same tests run as part of a deployment or validation do not show these failures.
A MIXED_DML_OPERATION error occurs in Apex when a test method performs DML operations on both setup objects (such as User or UserRole) and non-setup objects (such as Account or Contact) in the same transaction, or when those operations occur across different transaction contexts without proper isolation.
This article explains why Salesforce Apex tests can fail with MIXED_DML_OPERATION when run in the User Interface but not during a deployment, and whether that difference is expected.
During deployments, Salesforce does not perform mixed DML operation checks. When tests are executed through the Salesforce User Interface, either through Run All Tests or by running an individual Apex test class, mixed DML operation checks are enforced. If the only differences between the User Interface test results and the deployment test results are MIXED_DML_OPERATION failures, this behavior is expected and by design.
The same behavior also occurs when you run tests outside of a deployment or validation scenario through the Metadata API. This is also expected behavior.
To learn more about how mixed DML operations work in Apex test methods and how to avoid this error, see Mixed DML Operations in Test Methods in the Apex Developer Guide.
000394229

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.