How to Fix MIXED_DML_OPERATION Error in Salesforce Flow
MIXED_DML_OPERATION errors occur in Salesforce when a single transaction tries to modify both setup and non-setup objects, which Salesforce disallows. To fix this in Flows, you must split these operations into separate transactions using different techniques depending on the Flow type, such as using screens or local actions in Screen Flows, asynchronous paths in Record-Triggered Flows, or Wait elements in Scheduled Flows. Another powerful approach is leveraging Platform Events to decouple operations across transactions. This guidance helps Salesforce professionals build reliable automations that avoid this common and confusing error.
- Split setup and non-setup object DML operations into separate transactions to avoid errors.
- Use Screen elements or local actions to commit transactions in Screen Flows.
- Utilize Asynchronous or Scheduled Paths in Record-Triggered Flows to separate DML actions.
- Employ Wait elements in Scheduled or Autolaunched Flows to end and start new transactions.
- Leverage Platform Events to continue processes in a new transaction and prevent MIXED_DML_OPERATION.
Salesforce Flow is a powerful automation tool, but like any tool, it can sometimes throw errors. Some are easy to understand, while others can be confusing if you are not familiar with how Salesforce transactions work. One of the most common errors is MIXED_DML_OPERATION. Let's see why and when it happens, and how to fix it. What is MIXED_DML_OPERATION Error and Why Does It Happen? In Salesforce, setup objects are records related to configuration and access, such as PermissionSetAssignment, or GroupMember. Non-setup objects are regular objects like Account, Contact, Case, or Opportunity. MIXED_DML_OPERATION error happens when the same transaction tries to make changes to both setup objects and non-setup objects. Salesforce blocks this because changes to setup data can affect access and security, so they are handled differently from normal business data. When a flow tries to update both types in one transaction, Salesforce throws the MIXED_DML_OPERATION error.