Courseiva

SF-PD2 Advanced Developer Fundamentals Practice Question

A developer is using the 'System.runAs()' method in a test class. What is the effect of this method on the test execution?

⚠ Common exam trap

Candidates incorrectly believe that System.runAs() bypasses governor limits or changes the execution context for the entire test class rather than just the specific block of code.

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

✓

It enforces the sharing rules and profile permissions of the specified user.

The 'System.runAs()' method allows the developer to test code in the context of a specific user. It enforces that user's FLS, profile, and sharing rules. This is essential for testing security-sensitive logic, ensuring that the code correctly handles different levels of data access. However, it does not bypass governor limits, and the user must be created before the test starts.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • ✗

    It grants the user 'Modify All Data' permissions for the duration of the block.

    Why it's wrong here

    The 'System.runAs()' method only enforces the permissions actually assigned to the user. It does not elevate the user's rights to 'Modify All Data' or any other administrative privilege. The purpose is to simulate the actual user experience, not to grant temporary, elevated access during the test execution process.

  • ✗

    It causes the test to ignore all governor limits.

    Why it's wrong here

    Governor limits are enforced regardless of the user context. 'System.runAs()' is purely for testing sharing and security configurations; it has no impact on the technical constraints imposed by the Salesforce platform. Testing performance and limits must be done independently of the user context in which the code is executed.

  • ✓

    It enforces the sharing rules and profile permissions of the specified user.

    Why this is correct

    This is the primary function of 'System.runAs()'. It allows developers to verify that their Apex code behaves correctly under different sharing models and permission sets. This is a critical practice for ensuring that security logic, such as record visibility, works exactly as expected in the production environment for various user roles.

  • ✗

    It creates a new transaction context for the user.

    Why it's wrong here

    While it changes the user context, it does not start a new transaction. The code within the block still runs within the same transaction as the rest of the test method. It is a context switch, not a transactional boundary, so any database operations performed inside the block remain subject to transactional rules.

About these practice questions

This SF-PD2 question is part of Courseiva's 226-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written and reviewed by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

Last reviewed September 2026 · checked against the official Salesforce exam blueprint

This SF-PD2 practice question is part of Courseiva's free Salesforce certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the SF-PD2 exam.