What Is Mixed DML Operation Error in Salesforce?

What This Error Means?

Mixed DML Operation error occurs when Salesforce identifies an attempt within a single transaction to modify setup object data (such as Users or Permissions) and business object data (such as Accounts or Custom Objects) at the same time. Salesforce does not permit the execution of these two updates together.

When this happens, Salesforce stops the transaction and throws the Mixed DML Operation error to prevent inconsistent data changes.

Common Error Message

You may see one of these messages:

  • MIXED_DML_OPERATION: DML operation on setup object is not permitted after you have updated a non-setup object
  • Mixed DML operation between setup and non-setup objects
These messages indicate the same issue: Salesforce won’t allow certain objects to be updated together.

Where This Error Commonly Occurs?

This error often appears in scenarios such as,
  • In Apex triggers that update user records along with other objects
  • During Flows or Process Builder automation that touches both setup and non-setup objects
  • In test classes that create users and business records in one method
  • CPQ or onboarding automation mixing access data with business records

Why This Error Happens?

Salesforce categorises objects into two groups,

Setup Objects

These are configuration or access control records, such as:

(Users, Profiles, Permission Sets, Groups, Roles, Queues)

Non-setup Objects

These are business data records, such as:

(Account, Contact, Opportunity, Case, Custom Objects)

Salesforce processes setup changes separately from business data to maintain security and data integrity. Updating both in the same transaction can cause conflicts, so the platform blocks it.

How to Fix the Mixed DML Operation Error?

Fix 1. Use Asynchronous Apex

Move setup-related DML to run asynchronously using:

  • @future methods
  • Queueable Apex

This splits operations into separate transactions, preventing the conflict.

Fix 2. Separate Logic in Code

Design your logic so that:

  • Setup objects are updated first or in a separate context
  • Business objects are updated separately
Avoid doing both in the same trigger, Flow, or class.

Fix 3. Handle in Test Classes

If the error shows up during deployment or testing:

  • Wrap setup DML in System.runAs()
  • Do business record updates outside that block
  • Use @TestSetup methods to create test data

This ensures setup and non-setup operations are isolated.

Fix 4. Review Automation and Dependencies

Check whether:

  • Flows
  • Process Builder
  • Approval Processes

are updating setup or non-setup objects in the same execution. Breaking these into separate actions fixes the Mixed DML conflict.

Best Practices to Avoid This Error

  • Don’t update User or Permission records inside business logic triggers
  • Use async processing for user-related updates
  • Test flows and automation in full execution context
  • Add clear fault handling in Flows when interacting with both object types

Who Should Fix This Error?

  • Salesforce Admins: review automation and Flow design
  • Developers: update Apex logic or refactor code to separate transactions

Get the latest tips, news, updates, advice, inspiration, and more….

Need help fixing this in your org?

Our Salesofrce experts can debug and resolve this issue quickly.