Pages

Tuesday, November 13, 2012

Field Tracking

Out-of-the-box, Salesforce.com provide field tracking for up to 20 fields for standard and custom object. For custom object, you need to enable it by edit the object enable "Track Field History".








Once enabled, you will find a button "Set History Tracking" in "Custom Fields & Relationships" related list. For standard object, it will be there by default.

From "Set History Tracking" button, select fields you want to track up to 20 fields and yay... DONE!!

But, for Long Text Area field, it will just show who changed the field and when, that's all, no more information about what is the prior value and new value :( :(

Using Workflow and Field Update we can achieve this:
1. Create another Long Text Area to hold the history, in this sample, let's call it Response History to store history of Response (a long text area field).

2. Create a workflow with criteria ISNEW() || ISCHANGED( Response__c ).

3. Create an immediate workflow action with field update to update Response History field using this formula: 

"Last Modified: " + LastModifiedBy.FirstName + ' ' + LastModifiedBy.LastName + ' ' + 
TEXT(DAY(DATEVALUE(LastModifiedDate))) + '/' + 
TEXT(MONTH(DATEVALUE(LastModifiedDate))) + '/' + 
TEXT(YEAR(DATEVALUE(LastModifiedDate))) + ' ' + 
CASE(LEFT(RIGHT(TEXT(LastModifiedDate),FIND(" ", TEXT(LastModifiedDate))-2),2), 
'00','08', 
'01','09', 
'02','10', 
'03','11', 
'04','12', 
'05','13', 
'06','14', 
'07','15', 
'08','16', 
'09','17', 
'10','18', 
'11','19', 
'12','20', 
'13','21', 
'14','22', 
'15','23', 
'16','00', 
'17','01', 
'18','00', 
'19','03', 
'20','04', 
'21','05', 
'22','06', 
'23','07','00')+ 
LEFT(RIGHT(TEXT(LastModifiedDate),FIND(" ", TEXT(LastModifiedDate))-4),6) 
+ BR() + "------" + BR() + 
PRIORVALUE( Response__c ) + BR() + 
Response_History__c

Please note this formula only work with user without daylight saving timezone, because it will manually parse the time from GMT to your timezone (in sample above to GMT+8), because as of now Salesforce.com do not have TIMEVALUE() function yet. Otherwise, you can only capture the date OR display it in GMT timezone.

Here is the screenshot of the result:



No comments:

Post a Comment