Salesforce Platform Developer I (legacy) — Question 185
How should a developer avoid hitting the governor limits in test methods?
Answer options
- A. Use @TestVisible on methods that create records.
- B. Use Test.loadData() to load data from a static resource.
- C. Use @IsTest (SeeAllData=true) to use existing data.
- D. Use Test.startTest() to reset governor limits.
Correct answer: D
Explanation
The correct answer is D because using Test.startTest() allows the test method to reset the governor limits, providing a fresh context for the test execution. Options A, B, and C do not directly address the reset of governor limits; instead, they focus on managing data visibility or loading, which do not prevent hitting the limits themselves.