Contents
Is there an exception for mixed DML operation?
2) Assuming you are not inserting or updating any other sobject other than user in after insert and before update trigger then there is no question of getting Mixed DML operation exception as you are not combining setup object with non setup objects.
How to avoid mixed DML operation error in Salesforce?
If we perform DML operation on standard/custom object records asynchronously (execute in future context), we can avoid MIXED-DML-OPERATION error. Performing DML operation on more than two or two standard/custom object in the same transaction this error will come.
Can you do DML on a setup sobject?
Mixed DML operations within a single transaction aren’t allowed. You can’t perform DML on a setup sObject and another sObject in the same transaction. However, you can perform one type of DML as part of an asynchronous job and the others in other asynchronous jobs or in the original transaction.
When to perform mixed DML operation in apex?
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).
Can you perform two types of DML at the same time?
However, you can perform one type of DML as part of an asynchronous job and the others in other asynchronous jobs or in the original transaction. This class contains an @future method to be called by the class in the subsequent example.
When to perform DML operation on standard / Custom object?
If we perform DML operation on standard/custom object and global objects (User, UserRole, Group, GroupMember, Permission Set, etc…) in same transaction this error will come. To avoid this error, we should perform DML operation on standard/custom object records in a different transaction.
When does apex throw mixed DML operation error?
In an apex method when you try to perform DML operations on both setup and non-setup objects, they don’t go well and it throws Mixed DML Exception. How can we avoid getting mixed DML Operation Error?
Why is DML currently not allowed in Salesforce?
Reason: When we try to pass dynamic values from the Visualforce Component to the Apex method, Salesforce does not allow us to put any DML operation on that data. Solution: To overcome this error, you need to allow the DML operations from the component.