MIXED_DML_OPERATION error in Salesforce

MIXED_DML_OPERATION error in Salesforce

You can easily run into this error if you are trying to perform DML on setup and non-setup objects in the same transaction.

Non-Setup objects are standard objects like Account or any custom object.

Setup objects are Group1, GroupMember, QueueSObject, User2, UserRole, UserTerritory, Territory, etc..

For example, you cannot insert an account and then insert a user or a group member in a single transaction.

Test methods allow for performing mixed DML operations between the sObjects listed earlier and other sObjects if the code that performs the DML operations is enclosed within System.runAs method blocks. This enables you, for example, to create a user with a role and other sObjects in the same test.

Leave a Reply