1

How can I query (SOQL/APEX/API) the feed tracking custom object fields that has CHECKED ENABLE FEED TRACKING? I'm looking to get the ONLY fields that has FEED TRACKING.

As shown the screen shot below, I like to query to see if the Age or Country or City has enabled feed tracking, is that possible to do?

enter image description here

2 Answers 2

1

You can query against FieldDefinition and utilize SOQL and the Tooling API.

To get fields that have Field History enabled, you can use SOQL.

SELECT QualifiedApiName FROM FieldDefinition 
WHERE EntityDefinition.QualifiedApiName = 'Account' AND IsFieldHistoryTracked = true

This will output all the fields that have field history enabled on the given object.


To get what the question is specifically asking for, fields enabled for Feed tracking, you need to use the Tooling API. This is within the Metadata field of FieldDefinition and is accessible if only one row is returned in the query.

Below is an endpoint tested in Workbench REST Explorer

/services/data/v48.0/tooling/query/?q=SELECT+Metadata+FROM+FieldDefinition+WHERE+EntityDefinition.QualifiedApiName='Account'+AND+QualifiedApiName='Name'

The return looks like the following - what you care about is trackFeedHistory

{
  "size" : 1,
  "totalSize" : 1,
  "done" : true,
  "queryLocator" : null,
  "entityTypeName" : "FieldDefinition",
  "records" : [ {
    "attributes" : {
      "type" : "FieldDefinition",
      "url" : "/services/data/v48.0/tooling/sobjects/FieldDefinition/Account.Name"
    },
    "Metadata" : {
      "businessOwnerGroup" : null,
      ....//took out a bunch of fields
      "summaryOperation" : null,
      "trackFeedHistory" : true,
      "trackHistory" : true
    }
  } ]
}
7
  • good thought about the fieldDefinition, when I run the query I get the following error message FieldDefinition: a filter on a reified column is required [EntityDefinitinId, DurableId]
    – Nick
    May 8, 2020 at 20:16
  • You got that error message with the query in my answer? I only get that error if I don't include EntityDefinition in my WHERE clause. You can't get all fields across all objects in one query - you have to specify. May 8, 2020 at 20:22
  • +1 sorry, I did not copy and paste your query but it seems like working without error BUT this is strange even though I triple check that my custom object is enabled feed tracking and I have field checked but when I run the above query obviously changing the qualified api name to my custom object but I get 0 results. Any thoughts ?
    – Nick
    May 8, 2020 at 20:35
  • I try to use trackFeedHistory and I get an error No such column on the entity FieldDefinition
    – Nick
    May 8, 2020 at 20:42
  • I totally spaced. I just realized you're looking at feed tracking and I gave you field history. What you're looking for is within Metadata which is only available through the Tooling API (not SOQL query). Give me a second to edit May 8, 2020 at 20:51
-1

For feedtracking, Salesforce will create a new object which can be accessed by suffixing __Feed to your custom object. You try querying with object __Feed along with your Age, country & City fields.

1
  • I don't see any fields in that __feed object
    – Nick
    May 8, 2020 at 19:02

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.