Activity › Forums › Salesforce® Discussions › What is System runAs in Salesforce?
-
What is System runAs in Salesforce?
Posted by Deepak on September 9, 2019 at 2:55 PMWhat is System runAs in Salesforce?
Saddam replied 6 years, 8 months ago 4 Members · 3 Replies -
3 Replies
-
Hi Deepak,
The system method runAs enables you to write test methods that change the user context to an existing user or a new user so that the user’s record sharing is enforced.
- [adinserter block='9']
-
Hi Deepak,
System runAs method can also be used to perform mixed DML operations in your test by enclosing the DML operations within the runAs block. In this way, you bypass the mixed DML error that is otherwise returned when inserting or updating setup objects together with other sObjects.
Thanks
-
Hi Deepak,
Generally, all Apex code runs in system mode, and the permissions and record sharing of the current user are not taken into account. The system method, System.runAs(), lets you write test methods that change user contexts to either an existing user or a new user. All of that user’s record sharing is then enforced. You can only use runAs in a test method. The original system context is started again after all runAs() test methods complete.
Log In to reply.