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
vijaya kudupudivijaya kudupudi 

getting Mixed DML exception in Future method

Hi All,

I'm getting Mixed DML exception in future method.

Actually, In the case trigger i got a Mixed DML exception when i try to insert CaseteamtemplateMember. I have resolved that mixed dml exception by using future method and done the insertion of caseteamtemplatemember record in future method. But, now i need to insert another object record in the future method after inserting caseteamtemplatemember record, here again I'm getting Mixed Dml exception in future method.

Can some help me on this, if we can over come this error in future method?.

Thanks & Regards,
Vijaya K.
HarshHarsh (Salesforce Developers) 
Hi Vijaya,
  • If we perform DML operations on standard/custom objects and global objects(User, UserRole, Group, GroupMember, Permission Set, etc…) in the same transaction, this error will come.
  • To avoid this error, we should perform DML operation on standard/custom object records in a different transaction.
  • In general, all the apex classes and apex triggers execute synchronously (execute immediately).
  • If we perform DML operation on standard/custom object records asynchronously (execute in future context), we can avoid MIXED-DML-OPERATION errors.
  • To execute logic asynchronously keep the logic in an apex method (in a separate apex class, not in the same apex trigger) which is decorated with @future annotation.
  • 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.
Please mark it as Best Answer if the above information was helpful.

Thanks.