Salesforce Platform Developer I (legacy) — Question 130
While working in a sandbox, an Apex test falls when run in the Test Framework. However, running the Apex test logic in the Execute Anonymous window succeeds with no exceptions or errors.
Why did the method fall in the sandbox test framework but succeed in the Developer Console?
Answer options
- A. The test method is calling an @future method.
- B. The test method has a syntax error in the code.
- C. The test method does not use System.runAs to execute as a specific user.
- D. The test method relies on existing data in the sandbox.
Correct answer: D
Explanation
The correct answer is D because tests in the Salesforce sandbox environment run in isolation and do not have access to existing data, which can lead to failures if the test relies on that data. The other options do not accurately represent the reason for the failure, as @future methods, syntax errors, and user execution contexts would not cause the discrepancy between the test framework and the Developer Console in this scenario.