Salesforce Decode
Salesforcedecode
Back to questions
ApexIntermediatemixed-dmlsetuppermissions

Handle mixed DML operations involving setup and non-setup objects

Real World Scenario

Apex creating User and Account in same transaction fails with MIXED_DML_OPERATION error.

Expected Answer

• Separate setup object DML (User, Group, Queue) from non-setup in different transactions • System.runAs workaround limited to test context—not production pattern • Use @future or Queueable to defer setup DML after non-setup completes • Dedicated admin service class for user provisioning async jobs • Document which objects are setup vs non-setup for team reference • Flow-based user creation using separate transaction boundaries • Test mixed scenarios explicitly in provisioning integration tests

Follow-Up Questions & Answers

Click to expand — each follow-up includes a direct, interview-ready answer

Direct answer: Separate setup object DML (User, Group, Queue) from non-setup in different transactions Also consider: System.runAs workaround limited to test context—not production pattern In practice: Use @future or Queueable to defer setup DML after non-setup completes Balance speed of delivery with maintainability.

Architect Perspective

Mixed DML surprises teams at go-live—architect provisioning as two-phase async workflow.