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
rruddrrudd 

Mixed DML Error

Our developer reported sudden mixed DML errors in code that has worked for months with no changes.  Any ideas why this happened between releases?
Vivek DeshmaneVivek Deshmane
Hi,
It will not be release issue, may be development team added some code which causing this issue.
Refer below links for more details.
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_dml_non_mix_sobjects.htm
http://stackoverflow.com/questions/2387475/how-to-avoid-mixed-dml-operation-error-in-salesforce-tests-that-create-users

Best Regards,
-Vivek
Amit Chaudhary 8Amit Chaudhary 8
There you cannot perform DML on what salesforce calls setup objects(User in this case) and non-setup object in the same context. There is a workaround that can be found here although 

To fix this issue please try below :-
1) Future Method http://amitsalesforce.blogspot.in/search/label/Future%20Method
2) RunAs if  you are using test class
System.runAs ( new User(Id = UserInfo.getUserId()) ) 
{ 
    ...your setup-object DML... 
}
http://salesforce.stackexchange.com/questions/66046/mixed-dml-operation-dml-operation-on-setup-object-is-not-permitted-after-you-ha?rq=1

How to avoid MIXED_DML_OPERATION error in Salesforce tests that create Users
http://stackoverflow.com/questions/2387475/how-to-avoid-mixed-dml-operation-error-in-salesforce-tests-that-create-users

MIXED_DML_OPERATION error in Salesforce Apex Trigger when updating User objects

http://stackoverflow.com/questions/10136237/mixed-dml-operation-error-in-salesforce-apex-trigger-when-updating-user-objects

Please let us know if this will help you

Thanks
Amit Chaudhary