I have custom object on which history traking in enabled on number of fields. How can at run time i can get number of fields in objects on which history tracking in enabled from apex soql

  • You may get a list of fields that are already tracked by querying and collecting the field names from custom_object_history__c object in a set, but if you enable something new until the field is edited there will be no reference in the history object. You can track only upto 30 fields, why not create a custom setting list and throw the fields? I know its a maintenance item to keep the list updated, but I guess this is one setting that you would not update a lot . – Rao Jul 20 '17 at 21:53
  • Maintaining a list manually defeats the purpose of having describe calls and is, ultimately, not scaleable. – DavidSchach Jul 20 '17 at 21:56

I can't find this in Apex, but I can find it in the Tooling API and in the Metadata API.

For the Tooling API, check the CustomField object: https://developer.salesforce.com/docs/atlas.en-us.api_tooling.meta/api_tooling/tooling_api_objects_customfield.htm

For the Metadata API, there is, for each field on an object, a "trackHistory" attribute. https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/customfield.htm

Andy Fawcett has written an Apex wrapper for the Metadata API. For more information, see https://andyinthecloud.com/category/metadata-api/ and https://github.com/financialforcedev/apex-mdapi.

(I'd go with the Metadata API and would use the wrapper. It's an easy deploy from the GitHub repository.

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.