Newer Version Available
SOQL with Archived Data
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 ParentId, FieldHistoryType, Field, Id, NewValue, OldValue FROM FieldHistoryArchive - Filtered on FieldHistoryType
-
1SELECT ParentId, FieldHistoryType, Field, Id, NewValue, OldValue FROM FieldHistoryArchive WHERE FieldHistoryType = ‘Account’ - Filtered on FieldHistoryType and ParentId
-
1SELECT ParentId, FieldHistoryType, Field, Id, NewValue, OldValue FROM FieldHistoryArchive WHERE FieldHistoryType = ‘Account’ AND ParentId=’906F00000008unAIAQ’ - Filtered on FieldHistoryType, ParentId, and CreatedDate
-
1SELECT ParentId, FieldHistoryType, Field, Id, NewValue, OldValue FROM FieldHistoryArchive WHERE FieldHistoryType = ‘Account” AND ParentId=’906F00000008unAIAQ’ AND CreatedDate > LAST_MONTH
| Functionality | Details |
|---|---|
| DATE LITERALS | yesterday, last_week, and so on |
| LIMIT | |
| WHERE | Filtering only on FieldHistoryType, ParentId, and CreatedDate |