# How do Mixed DML Errors happen in triggers (e.g., creating a User and an Account in the same transaction) and how do you resolve them?

**Topic:** Apex Trigger · **Difficulty:** Medium · **Asked at:** Deloitte, PwC, Accenture · **Tags:** apex-trigger, trigger, mixed-dml, async

Read it on the site: https://www.forcechallenges.com/interview-questions/how-do-mixed-dml-errors-happen-in-triggers-e-g-creating-a-user-and-an-account-in-the-same-transaction-and-how

## Answer

Mixed DML error (`MIXED_DML_OPERATION`) occurs when setup objects (User, Group, GroupMember, PermissionSetAssignment, UserRole, etc.) and non-setup objects (Account, Contact, custom objects) are modified in the same transaction.

**Solutions:**
- Move the setup-object DML (or the non-setup one) to a separate transaction using `@future` or Queueable Apex.
- In tests, wrap one side in `System.runAs()`.

```apex
@future
public static void assignPermSet(Set<Id> userIds) { /* insert PermissionSetAssignment */ }
```

---
Source: ForceChallenges · last updated 2026-10-21
