Tuesday 23 October 2012

Tracking Long Text Area Fields - Work Around

Many times we are in definite need of Tracking Long Text Area fields in Salesforce.
We have two ready functionalities provided by salesforce to track fields,

1. Field History Tracking (FHT)
When a field is modified in a record for which FHT was enabled, then both the old and new field values were tracked.
Tracking them is possible via Report.

Example, if we have a custom Object called "Deal" then Deal History ReportType need to be used.
You need to enable Field History Tracking for the fields that you need to track in the Deal Object.
In the Deal History Report, you will find 3 fields,

a). Field/Event (which is the field you enabled for tracking)
b). Old Value (Old value of the field which is tracked)
c). New Value (New value of the field which is tracked)

2. Chatter Feed Tracking
When Chatter Feed was Enabled for an Object, you can see the Chatter embedded on every record associated with the object.
Feed Tracking need to be enabled for the fields, and Chatter Post will be created automatically whenever the field changes occur

a) Field which was changed
b) Old Value of the Field
c) New Value of the Field
d) User who made the change
e) Time of change.

Although these two functions were good, they have exceptions to fields such as long text areas and multi-select picklists.
Both FHT and Chatter Feed Tracking will indicate that the Long Text Area field was changed, but their old and new values were not recorded.

We can have this piece of Trigger to have the changes tracked via Chatter Posts, if you are in definite need of tracking Long Text Area field

trigger ChatterUpdatesTextArea on Opportunity (after update) 
{
    Map<id opportunity=""> oldmap=new Map<id opportunity="">();
    List<feeditem> fi=new List<feeditem>();
    for (Opportunity o : trigger.new)
    {
        if(o.Conditions__c!=System.Trigger.oldMap.get(o.Id).Conditions__c)
        {           
            FeedItem f=new FeedItem();
            f.ParentId=o.Id;
            f.Title=o.Name;
            f.Type='TextPost';             
            f.Body='changed Conditions from '+
                   System.Trigger.oldMap.get(o.Id).Conditions__c+
                   ' to '+o.Conditions__c;                            
            f.CreatedById=o.LastModifiedById;
            fi.add(f);                                  
        }
    }    
    insert fi;                    
}




 
Agree that it will be untidy as huge amount of text will be chattered, take a decision before using it:)

Otherway of doing it to create two new fields and populate them with the Trigger whenever the Long Text Area field in question is changed,
1. Field to hold the Old Value
2. Field to capture the User who is changing the value.

Run a report with Original Field and the Field holding its Old Value, which will be a one step process of tracking and not a history track.

2 comments:

  1. What is the better way for tracking long text field, Chatter Feed or having 2 fields? Can we limit chatter feed records to certain number?

    ReplyDelete
  2. Enter 360SMSApp, the leading solution for SMS integration within Salesforce. In this comprehensive guide, we will explore the benefits of SMS integration, how it can enhance your Salesforce experience, and why 360SMSApp is the top choice for businesses looking to leverage the power of SMS for Salesforce.

    ReplyDelete