A developer needs to implement a system audit feature that allows users, assigned to a custom profile named
"Auditors", to perform searches against the historical records in the Account object. The developer must ensure the search is able to return history records that are between 6 and 12 months old.
Given the code below, which select statement should be inserted below as a valid way to retrieve the Account History records ranging from 6 to 12 months old?

Correct Answer: B
Given the code snippet, the correct query to retrieve Account History records between 6 and 12 months old would be the one that includes a WHERE clause filtering records where the CreatedDate is greater than or equal to initialDate and less than or equal to endDate. Option B's statement does this correctly by using the >
= and <= operators to define the range between initialDate (which is set to today's date minus 12 months) and endDate (set to today's date minus 6 months). Options A, C, and D either use incorrect comparison operators or compare against the wrong variables, resulting in an incorrect data set being returned.
References
* SOQL Date Formats and Date Literals: SOQL and SOSL Reference Guide
Recent Comments (The most recent comments are at the top.)
Query should be:
SELECT Id, Field, OldValue, NewValue, CreatedDate, AccountId
FROM AccountHistory
WHERE CreatedDate >= :initialDate
AND CreatedDate <= :endDate
It should be queried from AccountHistory object, Account__History does not exist.
https://developer.salesforce.com/docs/atlas.en-us.sfFieldRef.meta/sfFieldRef/salesforce_field_reference_AccountHistory.htm