Activity Forums Salesforce® Discussions How can we run a particular test method by a different user other than the user which is currently active in salesforce org?

  • How can we run a particular test method by a different user other than the user which is currently active in salesforce org?

  • sushant

    Member
    January 31, 2017 at 1:56 pm

    Hi All,

    How can we run a particular test method by a different user other than the user which is currently active in org?

    Thanks

  • Kumar

    Member
    February 2, 2017 at 3:26 pm

    Hi Sushant,

    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.

    Refer to this:

    https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_tools_runas.htm

Viewing 1 - 2 of 2 posts

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos