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
santosh kottesantosh kotte 

@Test class

What is System.runas() in test classes ?when we use it ?can anyone give clear explation please.
Best Answer chosen by santosh kotte
Vatsal KothariVatsal Kothari
Hi,

Generally, all Apex code runs in system mode, where the permissions and record sharing of the current user are not taken into account. 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. The runAs method doesn’t enforce user permissions or field-level permissions, only record sharing.

You can use runAs only in test methods. The original system context is started again after all runAs test methods complete.

The runAs method ignores user license limits. You can create new users with runAs even if your organization has no additional user licenses.


You can refer below link:
https://developer.salesforce.com/page/Apex_Testing_with_RunAs

If this solves your problem, kindly mark it as the best answer.

Thanks,
Vatsal