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
Karthik ManoKarthik Mano 

Mixed DML Operation

Hi,

I am inserting new User in After insert and updating existing Users in before Update trigger on Contact. But it doesn't throw me the Mixed DML Operation between setup and non setup objects.

I am doubting if this is any bug in Salesforce or is this the expected function? Because i have previously gone for @Future methods when doing these kind of DMLs. But it doesn't throw me any exception in this case on trigger and the Contact as well as User DMLs are successful.

Any view on this will be helpful. Thanks.
Amit GhadageAmit Ghadage
Hi Kathik,
There are two possibilities so you are not getting exception 
1) I think you are not getting Mixed DML Operation because after insert and before update are two different transactions, Mixed DML operations are not allowed in single transaction (check debug logs if u have CODE_UNIT_STARTED 2 times under event tab)
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.

Best Regards,
Amit Ghadage
Karthik ManoKarthik Mano
Amit, Thank you. Is the Contact inserted by Salesforce to the database as a result of User creating the record not considered as a DML? I am in an assumption that, this insert of Contact to the database is a DML (by Salesforce) and me performing an explicit DML on User through trigger is the next DML which should cause a MIXED_DML operation. So, isn't the first one not considered as a DML activity?

Thanks
Amit GhadageAmit Ghadage
Karthik, Contact inserted by Salesforce to the database as a result of User creating the record not considered as a DML. you can check this by inserting a record in Object having no trigger and see debug log.. there will be no SOQL used.

Best Regards,
Amit Ghadage