1

I've been reading up on queries via the API. This post here on histories from custom objects and how to make sub-queries have been very useful.

I'm doing blind iterations through the schema - ie, the code I write needs to grab data on any object and be robust as we add new ones.

Currently it all works but isn't grabbing histories - I figure that's because I need to ask it to query the My_Custom_Object__History from each My_Custom_Object__c. Ideally though, I want an insight into if a record has a history before I fire my request.

I was looking through the rest explorer to see if there was a Has_history:true or Historible:true kind of parameter on object describe (everything there seems to end in -able!).

If I could find some indicator I could do something like:

@s_object.get_history if @s_object.has_history and save myself futile queries and error handling.

Then... assuming Histories is a common name across all objects I could just poll Select Id, Name, (Select Id From Histories) From Custom_Object__c

Worst case I guess I just have to do the above line and then ignore if nil/null

Anyone done anything similar or got any insight?

2

After taking my own look through the REST explorer, there isn't an attribute that you get from the sobject describe result, nor from the basic object information result, that tells you if history tracking is enabled on an object. It exists as an attribute in the actual object metadata, but it does not appear to be available through anything in the REST API.

About the only thing that I can think of is to iterate over the Child Relationships that you get from the API call for the sobject describe result, and look for Histories or <sObject Name here>Histories.

You do have to take care though, there are at least some sObjects that have more than one child relationship with Histories in the name.

Opportunity, for example, has the following child relationships (among others)

  • ActivityHistories
  • Histories
  • OpportunityHistories

Of those, Histories, which references the OpportunityFieldHistory object, is probably what you want.

I believe that Opportunity is an exception, and that the history object for most other objects follows the pattern <standard sObject Name>History or <custom sObject Name>__History. The child relationship name appears to be simply Histories in all cases.

  • ... Ima gonna open a support ticket to rename the Histories.Histories to Historiography – Huw Jul 29 '16 at 14:14
  • Thanks for addressing this so logically, highlighting the objects to take care of is also very useful. I guess I'm resigned to burning a few more API calls on querying and then doing .count of arrays on history. Would of thought HasHistory would be a great parameter for parents, but ¯\_(ツ)_/¯. Cheers! – Huw Jul 29 '16 at 14:16

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.