Sunday, August 4, 2013

Salesforce: Enable Feed Tracking versus Set History Tracking

Few months back, I wrote a blog on Chatter feed item and the structure, that blog explain on "Feed Tracking" and the data structure. When selected fields are enable for feed tracking, any changes to those fields will be shown in the record Feed. You can find this feed at top of page layout,

If user change value of more than 1 field in one update, it will be captured into only one feed (no matter how many fields are changed).

You can hide feed by click "Hide Feed" link or click "Fewer Updates" in Show: to show only feed created manually (Feed automatically created by Feed Tracking will not shown).

Feed Tracking is stored in a new object, end with suffix Feed (for Standard object) or __Feed (for Custom object). If you dig further, records created by feed tracking have API Type = TrackedChange, for other Type:
  • ContentPost - an uploaded file on a feed
  • LinkPost - a URL posting on a feed
  • PollPost - a poll posted on a feed
  • TextPost - a direct text entry on a feed
You also can find the exact same value in FeedItem object (with API version 23.0 or later).
SELECT Id, CreatedDate, CreatedById, CreatedBy.FirstName, CreatedBy.LastName, ParentId, Type, Parent.Name, Body,
(SELECT ID, FieldName, OldValue, NewValue FROM FeedTrackedChanges ORDER BY ID DESC)
FROM FeedItem
From above query, you can see FeedTrackedChange is linked to FeedItem object (using FeedItemId field) and use to store field name, old and new value. FeedTrackedChange object start with prefix 0D6 and FeedItem start with prefix 0D5. 

While for Set History Tracking, it have almost the same function with feed tracking to track field change, but it stored in different object and for different purpose.

1. Record end with prefix History (for Standard object) or __History (for Custom object).

2. Every field change will have own record in history object, and directly linked to the ParentId.

3. User can easily run History report to display values change related to the object.