12

Is there a way to access with Apex the list of the fields that are tracked in the account history? enter image description here

I haven´t found a describe call for this purpose.

1
  • This was not as useful as I was hoping it would be: AccountHistory.Field.getDescribe().getPicklistValues().
    – martin
    Commented Sep 7, 2015 at 10:14

2 Answers 2

10

Since Winter '16 this can be achieved using the IsFieldHistoryTracked field on FieldDefinition.

To get all tracked fields on Account you can use:

SELECT QualifiedApiName FROM FieldDefinition WHERE EntityDefinition.QualifiedApiName = 'Account' AND IsFieldHistoryTracked = true
3

There is another question however the solution was not accepted as an answer: Apex: Is there a way to Identify if history tracking is enabled on my field or not?

I think there is no clean way of doing this.

Every object that has history enabled has a special table by the name "Custom_Object_History" or "StandardObjectHistory".

You can run the following query on that object:

SELECT count(Id),Field FROM Custom_Object__History group by Field

The result will be something like

Count     Field
1         Contract_Term__c
12        Contract_Expiry_Date__c
1         Type_of_Service__c

Using this you can get the field API names.

If your field API Name is present, the you have History Enabled on that field.

This may however give you the field history for past as well. You can put a date clause I guess.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .