Newer Version Available

This content describes an older version of this product. View Latest

SOQL with Archived Data

You can use SOQL to query archived fields.

The allowed subset of SOQL commands lets you retrieve archived data for finer-grained processing. You can use the WHERE clause to filter the query by specifying comparison expressions for the FieldHistoryType, ParentId, and CreatedDate fields, as long as you specify them in that order. That is, if you filter by using ParentId or CreatedDate, you must also filter by using the preceding fields. The final comparison expression in the query can use any one of the comparison operators =, <, >, <=, or >=. Any other comparison expression can use only the = operator. You can’t use the != operator.

You can use the LIMIT clause to limit the number of returned results. If you don’t use the LIMIT clause, a maximum of 2,000 results are returned. You can retrieve additional batches of results by using queryMore().

Examples: Allowed Queries

1SELECT fieldList 
2FROM FieldHistoryArchive
3[WHERE FieldHistoryType expression [AND ParentId expression[AND CreatedDate expression]] ]
4[LIMIT rows]
Unfiltered
1SELECT * FROM FieldHistoryArchive
Filtered on FieldHistoryType
1SELECT * FROM FieldHistoryArchive WHERE FieldHistoryType = ‘Account’
Filtered on FieldHistoryType and ParentId
1SELECT * FROM FieldHistoryArchive WHERE FieldHistoryType = ‘Account’ AND ParentId=’906F00000008unAIAQ’
Filtered on FieldHistoryType, ParentId, and CreatedDate
1SELECT * FROM FieldHistoryArchive WHERE FieldHistoryType = ‘Account” AND ParentId=’906F00000008unAIAQ’ AND CreatedDate > LAST_MONTH
The following table describes the SOQL functions that are available for querying archived fields.

All number fields that are returned from a SOQL query of archived objects are in standard notation, not scientific notation as in the number fields in the entity history of standard objects.

Note

Table 1. SOQL Functions Available for Archived Fields
Functionality Details
DATE LITERALS yesterday, last_week, and so on
LIMIT
WHERE Filtering only on FieldHistoryType, ParentId, and CreatedDate