I've grappled with this one for a long time, and I am almost sure it's a gap in the platform. The problem I have is that I need a way to find out all the fields that can be tracked. That is to say, all of the fields that would be visible in the setup menu if you went to an object and tried to track fields.
The metadata api seemed to be a logical contender for this purpose. And it was! It was working swimmingly for standard objects. Even standard objects with custom fields were a-ok. However, if you read (or retrieve) the CustomObject metadata for a custom object OR the CustomField metadata from a field on a custom object, the trackHistory value does not come back or comes back as null.
So for standard objects, I am able to tell the total amount of trackable fields by reading metadata for all the fields on the object, and noticing which values come back as true or false rather than null.
But since I am not able to get the trackHistory value back from fields on custom objects, I can't tell which fields on the custom objects can be tracked.
I am able to tell which fields ARE tracked on the custom objects by heading to the FieldDefinition Tooling API table. There is a field on that table titled
IsFieldHistoryTracked. That field actually tells you if the field is tracked or not (contrary to the docs, which SAY that it is supposed to show if "the field’s history can be tracked", but i digress).
HOWEVER, just knowing that the field is tracked is not enough, as all of the fields that can or cannot be tracked have a true / false value in this field.
So, does anyone know of a way out of this for me? Is there any real way to figure out which fields can and can not be tracked programmatically? Do I have to scrape the menu screen (60% joking).
Any and all help is much appreciated.
<trackHistory>true</trackHistory>on custom object fields for me