Why are we getting MIXED_DML_OPERATION Exception ?
Because it will occur when you try performing DML operation on a setup object and non-setup object in same transaction,
Following are the setup objects where you can’t perform mixed DML operations in same transaction,
You can only insert and update a group in a transaction with other sObjects. Other DML operations aren’t allowed.
You can perform DML operations on more than one type of sObject in a single class using the following process:
- Create a method that performs a DML operation on one type of sObject.
- Create a second method that uses the future annotation to manipulate a second sObject type.