SF-PD2 Advanced Developer Fundamentals Practice Question
A developer needs to write an Apex test method that verifies a trigger correctly updates a related Contact when an Account is inserted. The trigger performs a SOQL query and a DML update. What must the developer do to ensure the test passes in a Salesforce sandbox?
⚠ Common exam trap
The trap here is thinking that SeeAllData=true is needed to test triggers that query existing records, when in fact tests should create their own data.
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 test data for the Account and insert it, then assert the Contact was updated.
For a trigger test to pass, the developer must create the test data that causes the trigger to fire, perform the DML operation, and then assert the expected outcome. Test.startTest() and Test.stopTest() are useful for limit isolation but not sufficient alone. Using SeeAllData=true is risky and unnecessary. Triggers cannot use with sharing. Thus, creating and asserting test data is the correct approach.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Set the trigger to run in system mode by using with sharing.
Why it's wrong here
Triggers run in system mode by default, meaning they ignore sharing rules. Using with sharing on a trigger is not valid syntax; sharing keywords apply to classes, not triggers. This option is incorrect both syntactically and conceptually, and it does not affect whether the test passes.
- ✗
Use the @isTest(SeeAllData=true) annotation to access existing records.
Why it's wrong here
Using SeeAllData=true is generally discouraged because it makes tests dependent on org data, which can lead to unpredictable results and deployment issues. It is not required to test a trigger; instead, the test should create its own data. This annotation does not ensure the test passes and may violate best practices.
- ✓
Create test data for the Account and insert it, then assert the Contact was updated.
Why this is correct
To test a trigger, the developer must create and insert the necessary test data (Account) within the test method, then perform the DML operation that fires the trigger, and finally query the Contact to assert the expected update. This is the fundamental requirement for a passing trigger test.
- ✗
Use Test.startTest() and Test.stopTest() to isolate the governor limits.
Why it's wrong here
Test.startTest() and Test.stopTest() are used to reset governor limits and to ensure asynchronous operations complete, but they do not guarantee that the test passes. While good practice, they are not the specific requirement to make the trigger test pass; the test must still create test data and assert results.
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.