Platform
MIXED_DML_OPERATION: separate setup and business writes
Diagnose mixed DML in Apex and Flow, separate incompatible writes and track asynchronous provisioning to completion.
Creating a business record and assigning permissions can fail when both happen in one transaction. Access-changing setup work may need a separate transaction.
Salesforce’s mixed-DML reference lists restricted setup objects and operation-specific exceptions. Don’t reduce the rule to “User can never be written with Account”: User behavior depends on the operation, fields and API version. Inspect the exact objects and fields in the failing path.
Trace indirect setup writes
A business-record save may invoke a flow that creates a user or assigns a permission set. The method in the stack trace may not perform both operations itself. Draw the complete save path, including related-record automation.
Identify which operation establishes the access model and which operation creates ordinary business data. Decide whether the caller requires both to finish immediately. If delayed provisioning is acceptable, a separate asynchronous transaction can provide the boundary.
That boundary changes failure handling. The first transaction can succeed while provisioning fails later. Store a pending status and a job reference, and give an operator a way to inspect the failed step. Don’t mark a user ready merely because the job was queued.
Make the provisioning operation repeatable
Before creating a user or permission assignment, check the intended identity and current state. A retry should not create another identity or grant a different permission set because an earlier step partially completed.
Keep the request’s business identifier stable across retries. Record the requested change, the approved scope and the confirmed result without exposing credentials. If provisioning requires approval, preserve that approval independently of the worker’s technical execution.
For a Flow implementation, confirm that the selected asynchronous path provides the intended transaction boundary for that flow type. Moving an element on the canvas doesn’t by itself prove that the writes are separated.
Test production behavior separately from test conveniences
The documentation includes mixed-DML handling for tests using System.runAs. A test-specific arrangement is not a production transaction strategy. Keep the distinction visible in code review.
Test the first transaction’s success, the provisioning worker’s success and a worker failure after the first commit. Include a repeated request and a request for an existing assignment.
The result should tell the caller whether the business record exists and whether provisioning is confirmed. If one remains pending, show that state. For related transaction-boundary decisions, see the async Apex guide.