function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Ashish PathaniaAshish Pathania 

MIXED_DML_OPERATION, DML operation on setup object is not permitted after you have updated a non-setup object (or vice versa): User, original object: Account: []

The actual code is running,
But while writting the unit testing it is giving the above error,
The code does a part where it updates the contact and user details of the user. This user which is being updated is not the logged in one.
Please guide.
Khan AnasKhan Anas (Salesforce Developers) 
Hi Ashish,

Greetings to you!

You need to use System.runAs around the Setup objects (https://developer.salesforce.com/docs/atlas.en-us.api_tooling.meta/api_tooling/reference_objects_setup.htm) to avoid the mixed DML error. Please refer to the below links which might help you further with the above issue.

https://salesforce.stackexchange.com/questions/211716/mixed-dml-operation-dml-operation-error-when-creating-user-role-record-in-test

https://www.redargyle.com/blog/handling-system-errors-unit-tests/

https://salesforce.stackexchange.com/questions/119807/mixed-dml-operation-error

https://help.salesforce.com/articleView?id=000325253&type=1&mode=1&language=en_US (https://help.salesforce.com/articleView?id=000325253&type=1&mode=1&language=en_US)

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas