Ask Question
12 August, 11:11

When writing test methods, what functionality is verified by the system method "runAs () "?

+5
Answers (1)
  1. 12 August, 14:54
    0
    The main functionality verified by this test method command is user sharing record.

    Explanation:

    Generally, every apex code runs in system mode.

    Apex is strong object-oriented programming language that allows the developers to execute flow and transaction control.

    Using syntax which look like java and acts as databases, Apex allows the developer to add any type of business logics to an event which can include button, clicks records or visual pages.

    Apex code can be initiated by web service request.

    The permissions and record sharing of current user are not consider by apex codes.

    Now the system method runAs () will allow you to take or write a test method which will basically change the user context to an existing or an new user, so that the record sharing will take place.

    runAs () command will not change or anything done with user permissions or permission levels, it will only record sharing of the user.

    When you use runAs () command the original and true context will run after the test method is once completed under the command of runAs ().

    The runAs () has no concern with the user license.

    If there is no or expired your personal or organization license you can just make a new user with this runAS () command.

    In using this command we have to make a private class by the name of this test and then our further code to make a user, afterwards which we will the true and original code of ours which we want to run.

    There are many other uses of runAs () like

     Mixed DML operations in test by opening the DML operations.

     We can also use it as a version which will take a package as a version argument. This will cause the code a specific version.

    runAs (System. Version) is the command used for this.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “When writing test methods, what functionality is verified by the system method "runAs () "? ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers