Courseiva

SF-PD2 Testing, Debugging, and Deployment Practice Question

A developer is preparing a deployment of a new Apex class and its test class to production. The test class uses @TestSetup to insert 200 Account records, and each of six test methods queries all 200 Accounts. The deployment fails during validation with a CPU timeout error. Which change most directly addresses the timeout without reducing coverage?

⚠ Common exam trap

The trap here is treating a CPU timeout as a setup-data problem and moving inserts around, when the dominant cost is the repeated broad query in each test method.

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

✓

Replace the full-object queries with selective SOQL that filters and returns only the fields and rows each test actually needs.

CPU timeouts in test execution usually trace to expensive query volume. Querying every row with every field six times forces the platform to materialize a large result set repeatedly. Tightening the SOQL so each test retrieves only the fields and rows it needs cuts CPU consumption directly while keeping the same behavioral assertions and coverage.

Answer analysis

Option-by-option breakdown

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

  • ✗

    Move the Account insertion into each test method instead of @TestSetup so each method gets a fresh set of records.

    Why it's wrong here

    Relocating the setup into every method increases total work, because the 200 Accounts are inserted six times rather than once. CPU time is consumed by DML and the repeated setup, so this change would worsen the timeout rather than relieve it. It also does not reduce the per-method query cost that drives the overage.

  • ✗

    Annotate the test class with @isTest(OnInstall=false) to defer test execution until after the package is installed.

    Why it's wrong here

    OnInstall controls whether tests run during a package install, not during a metadata deployment validation. It does not reduce the CPU consumed by the test methods themselves, so the timeout during validation would persist. The annotation also cannot be applied to change deployment behavior for an unpackaged class in this scenario.

  • ✗

    Convert the test methods to use System.runAs() so the queries execute under a user with fewer permission checks.

    Why it's wrong here

    System.runAs() changes the running user context and is valuable for permission and sharing tests, but it does not reduce the volume of rows returned by a query. The CPU cost of materializing 200 records per method remains unchanged. Using runAs here adds complexity without addressing the root cause of the timeout.

  • ✓

    Replace the full-object queries with selective SOQL that filters and returns only the fields and rows each test actually needs.

    Why this is correct

    CPU time in tests is dominated by query processing, and selecting all 200 rows with every field across six methods multiplies that cost. Filtering rows and projecting only required fields reduces the rows and columns the query engine must materialize, lowering CPU consumption while still exercising the same logic. Coverage is preserved because each test still validates the behavior it targets.

About these practice questions

One of 226 original SF-PD2 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. 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.