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
Lakshmi SLakshmi S 

Exception handling

HI All,

How to Avoid MIXED DML Operation exception in Salesforce ?

can anyone reply for this post...
Thanks in Advance..
Best Answer chosen by Lakshmi S
Amit Chaudhary 8Amit Chaudhary 8
Please check below post for same
1) http://www.tgerm.com/2012/04/mixeddmloperation-dml-operation-on.html
2) https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_dml_non_mix_sobjects.htm

DML operations on certain sObjects, sometimes referred to as setup objects, can’t be mixed with DML on other sObjects in the same transaction. This restriction exists because some sObjects affect the user’s access to records in the org. You must insert or update these types of sObjects in a different transaction to prevent operations from happening with incorrect access-level permissions. For example, you can’t update an account and a user role in a single transaction. However, deleting a DML operation has no restrictions

To resolved this issue we can use below
1) Future method for Apex class
2) RunAs User for Test class
 

All Answers

BALAJI CHBALAJI CH
Hi Lakshmi Narasimha,

You can use Future Method to Perform Mixed DML Operations.
Please find below link for an example and more information.
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_dml_non_mix_sobjects.htm

Let me know if that helps you.
Best Ragrds,
BALAJI
Amit Chaudhary 8Amit Chaudhary 8
Please check below post for same
1) http://www.tgerm.com/2012/04/mixeddmloperation-dml-operation-on.html
2) https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_dml_non_mix_sobjects.htm

DML operations on certain sObjects, sometimes referred to as setup objects, can’t be mixed with DML on other sObjects in the same transaction. This restriction exists because some sObjects affect the user’s access to records in the org. You must insert or update these types of sObjects in a different transaction to prevent operations from happening with incorrect access-level permissions. For example, you can’t update an account and a user role in a single transaction. However, deleting a DML operation has no restrictions

To resolved this issue we can use below
1) Future method for Apex class
2) RunAs User for Test class
 
This was selected as the best answer
Rakesh51Rakesh51
You have two options
1) Use @future method
2) Use time-based actions