Loading

Salesforce Apex Test Failure Due to 'MIXED_DML_OPERATION' Seen in User Interface but Not in Deployment

Data pubblicazione: Oct 12, 2026
Descrizione

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.

Risoluzione

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.

Why MIXED_DML_OPERATION Failures Appear Only in the User Interface

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.

MIXED_DML_OPERATION Behavior When Running Tests Through the Metadata API

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.

How to Avoid the MIXED_DML_OPERATION Error

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.

Risorse aggiuntive
Numero articolo Knowledge

000394229

 
Caricamento
Salesforce Help | Article