0

Is there any way to Chatter Feed Tracking programatically for a field which is long / rich datatype in salesforce.com?

I tried to do this using salesforce standard way but was not able to get the old and new value in chatter using set history tracking button.

But for normal fields , i am getting new/old value in chatter.

I came to know that the chatter standard way doesnot give old and new value for fields with characters more than 256 .

Can some let me know how this can be achieved.

Best regards, Ankita

  • Can someone help me on this?? – Ankita Singh Sep 2 '15 at 9:04
3

Thank you guys for your help.I was able to achieve something like this.Posting the answer as it might help others also.

  list<FeedItem> lstFeedItem = new  list<FeedItem>();
for(account acc : trigger.new ){
    if(acc.Tracking_Field__c != trigger.oldMap.get(acc.Id).Tracking_Field__c ){
        FeedItem objFeedItem = new FeedItem();
        objFeedItem.ParentId = acc.Id;
        objFeedItem.Body = 'changed Tracking field from '+ trigger.oldMap.get(acc.Id).Tracking_Field__c +' to '+ acc.Tracking_Field__c ;
        objFeedItem.Type = 'TextPost';
        objFeedItem.NetworkScope = 'AllNetworks';
        lstFeedItem.add(objFeedItem);
    }

}

insert lstFeedItem;

}

  • 1
    Thanks for sharing that! To make your code more robust, you should take the maximum length of FeedItem.Body into account. It's currently 10,000 characters. If you try to set the Body larger than that, your trigger will throw an exception when it tries to insert the list of feed items. – alouie Sep 10 '15 at 6:30
2

There's no way to configure Chatter to display the old and new values for Long Text Areas and Rich Text Areas. The automatically generated "feed tracked change" post will only indicate that the value was updated.

You'd need to write an Apex trigger to post a feed item containing the old and new values. It's not possible to format it like the automatically generated posts, though.

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.