I am trying to update a user & contact object in the same transaction, just to do some analysis on that mixed_dml_operation error which we usually get in the case of DML on setup & non-setup objects in the same transaction.

I am wondering why I'm unable to see that error when trying to update records with the below code.

public void checkMixedDml(){
 Account account1 = [Select Id,name from Account limit 1];
 account1.name = 'test';
 update account1;
 User objUser = [Select Id from USER where Id =:UserInfo.getUserId()];
 objUser.lastname = 'TestLastName';
 update objUser;


The above code is not throwing any error and working fine when executing from the Anonymous window. Any reason?


  • Neither object is a setup object, to get the exception try adding a Queue record with the Account. Commented May 17, 2021 at 9:20

1 Answer 1


There is nothing wrong with the DML operations you are completing here, simply because of the field you are updating on the User object. A MIXED_DML_OPERATION exception will only be presented when certain fields (i.e relationships to setup objects) are populated on the User and certain class APIs are used. See sObjects That Cannot Be Used Together in DML Operations.

A quick test in your anon apex code would be to set the UserRoleId on the User object your are updating.

Note, this is commonly encountered in test methods as those setup objects are related to the User being tested i.e Queues, Permissions, Roles, Territories e.t.c

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .