8

I tried Object.Field.getDescribe(); But, it doesn't have a parameter to identify if history tracking is enabled for a field or not. Is there any other way to identify all fields on my custom object with field history tracking enabled?

I have a custom object Steps__c [track history enabled] with 10 different fields out of which 2 fields "Status__c" and "Task_Status__c" have field history tracking enabled. I need a Vf page to show me only fields on Steps__c with history tracking enabled. Basically - show only Status__c and Task_Status__c in a selectList.

3

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

To get all tracked fields on Steps__c you can use:

SELECT QualifiedApiName FROM FieldDefinition WHERE EntityDefinition.QualifiedApiName = 'Steps__c' AND IsFieldHistoryTracked = true
| improve this answer | |
2

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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.