[SalesForce] History tracking of object

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

Best Answer

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.