SF-PD2 Process Automation, Logic, and Integration Practice Question
A developer is writing a test class for an Apex trigger that creates a related record when an Account is inserted. The test must verify that the related record is created and that a validation rule prevents creation when the Account's AnnualRevenue is null. What is the best practice to ensure the test covers both scenarios?
⚠ Common exam trap
The trap here is assuming that a single test method can cover multiple scenarios without interference, or that Test.startTest and Test.stopTest alone can ensure coverage.
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
✓
Create separate test methods for each scenario, using Test.startTest() and Test.stopTest() around the DML operation.
The best practice is to write separate test methods for each scenario to isolate failures and ensure clarity. Wrapping the DML operations in Test.startTest and Test.stopTest resets governor limits and ensures any asynchronous processing completes. This allows the developer to assert that the related record is created for valid Accounts and that the validation rule fires for Accounts with null AnnualRevenue, achieving comprehensive test 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.
- ✗
Use Test.startTest() and Test.stopTest() to isolate the trigger execution and then assert the results.
Why it's wrong here
Test.startTest and Test.stopTest are used to isolate governor limits and asynchronous execution, but they do not by themselves ensure coverage of both scenarios. They are helpful but not the primary method for testing multiple conditions. The developer must still create separate test methods or use multiple assertions within a single method.
- ✗
Use a single test method that inserts both a valid and an invalid Account, then asserts the results.
Why it's wrong here
Combining both scenarios in one test method can cause interference, such as the invalid Account causing an exception that aborts the test before asserting the valid case. It also makes debugging harder. Separate methods are preferred for clarity and to ensure each scenario is independently verified.
- ✓
Create separate test methods for each scenario, using Test.startTest() and Test.stopTest() around the DML operation.
Why this is correct
Best practice is to write separate test methods for different scenarios to isolate failures and ensure comprehensive coverage. Using Test.startTest and Test.stopTest around the DML operation resets governor limits and ensures that asynchronous processes complete before assertions. This approach tests both the successful creation and the validation rule preventing creation with null AnnualRevenue.
- ✗
Use @isTest(SeeAllData=true) to access existing Accounts and then assert the trigger behavior.
Why it's wrong here
Using SeeAllData=true is discouraged because it makes tests dependent on org data, reducing reliability and portability. It does not help in testing the two scenarios; the developer should create test data within the test. This option violates best practices for test isolation and does not address the need to test both conditions.
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 →
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.