SAP Open Connectors

Salesforce Sales Cloud - How to Track the Field Change History for Different Resources

To retrieve the change history for a certain resource, use the Salesforce /query endpoint. This is an undocumented API on the Salesforce Sales Cloud connector that lets the user pass a SOQL query directly to Salesforce.

Prior to making the request itself, there are some settings to be configured in the Salesforce UI to enable the field history tracking. The steps to be taken are reflected in the following Salesforce article for standard objects: and in this one for custom objects:

After configuring the field history tracking for the desired fields, the request can be made in Postman or any other tool using the /query endpoint mentioned above. It should have the structure as presented below, with a q(query) parameter having an SOQL statement as its value and the selected fields (id, NewValue, OldValue, Field) depending on what resource the user is going to query. We would suggest checking the documentation in order to correctly provide the field names in the query: (this is for the AccountHistory resource, but searching the page for the word "history" will provide all the resources for which we can track the history of the fields).

The GET request example: 

curl -X GET \
  'https://{staging OR api}.cloud-elements.{com OR}/elements/api-v2/query?q=SELECT id, NewValue, OldValue, Field from AccountHistory' \
  -H 'Authorization: User xxxxxxxxxxx, Organization xxxxxxxxxxx, Element xxxxxxxxxxx' \

The response payload has the following structure: 

        "Field": "TextName",
        "NewValue": "Alex Entity",
        "IsDeleted": false,
        "Id": "xxxxxxxxx",
        "OldValue": "Alex Str"

More information about the query endpoint can be found here.