Certified Platform Developer II Exam QuestionsBrowse all questions from this exam

Certified Platform Developer II Exam - Question 246


A developer wrote a class named AccountHistoryManager that relies on field history tracking. The class has a static method called getAccountHistory that takes in an Account as a parameter and returns a list of associated AccountHistory object records.

The following test fails:

What should be done to make this test pass?

Show Answer
Correct Answer: CD

To make the test pass, @isTest(SeeAllData=true) should be used to allow the test to access historical data from the org. This is required because field history tracking data is not copied to a test context, so you need to allow the test to access live data to assert against it. The other options would either not work or would be against best practices. Using @isTest(SeeAllData=true) allows the test method to access the historical data, making the test accurate and valid.

Discussion

2 comments
Sign in to comment
M4JK3LSONOption: C
Dec 21, 2023

C can be good answer, because standard field tracking mechanism do not apply for apex tests

Vikas_08Option: D
Apr 25, 2024

ANSWER is D Explanation- To make the test pass, @isTest(SeeAllData=true) should be used to allow the test to access historical data from the org. This is required because field history tracking data is not copied to a test context, so you need to allow the test to access live data to assert against it.References: Apex Developer Guide - IsTest Annotation