MIXED_DML_OPERATION, DML operation on setup object is not permitted

You should use @future class to avoid this error, as described in the Apex Developer Guide.


We cannot perform DML Operation on both Setup and Non-setup object in a same context of execution. The trigger is firing because of DML on User object, and you are trying to insert Contact record in the same context. That's why you are getting this error.

If you remove insert statement for contact record, then it will work fine. Although if you need to perform DML on contact as well, then use @Future annotation.

Tags:

Dml

Apex

Trigger