How to do DML Operations on USER Context in Apex?

Salesforce Spring 23 release introduced a new feature USER_MODE. By default, salesforce performs dml operations on system context, with this new release spring 23, we can use USER_MODE to run DMLs on user context. here are the examples for how we can do DML operations on user and system context.  

Example DML Operations system mode

Account acc = new Account(Name='test');
Insert acc;

Example DML Operations User mode

Account acc = new Account(Name='test');
Insert as user acc;
Labels:
DML
Join the conversation