Ask Search:
Naveen PeriyasamyNaveen Periyasamy 

How to track history of record views in Salesforce?

We would like to track history of record views in custom objects, we were aware of field history tracking, but that only tracks updates not the views.

Please let me know if anyone has an answer
Evan DeckerEvan Decker
I'm pretty sure this is not possible.
Naveen PeriyasamyNaveen Periyasamy
Hi Evan & Naman,

Thanks for your reply, I have found a useful link to solve this issue but haven't tried it yet.

http://boards.developerforce.com/t5/General-Development/Tracking-when-a-user-views-a-record-in-Salesforce/td-p/392943

Regards,
Naveen
Evan DeckerEvan Decker
Which solution in that thread are you going to try?
Deepak AnandDeepak Anand
Hey Naveen,

Just a quick question: Are you at least on a Professional Edition + API Add-On ? If so I could think of something like this:

(i) Create a field on the Custom Object say 'Record View Count(Record_View_Count__c)' of type - Number(18,0).

(ii) Then create a Visualforce Page like this:

Label: Record View Tracker
Name: RecordViewTracker

<apex:page standardController="Opportunity">
   <apex:includeScript value="/soap/ajax/28.0/connection.js"/>
   <script type="text/javascript">
       sforce.connection.sessionId = '{!GETSESSIONID()}';

       var object = new sforce.SObject('Opportunity');
       object.Id = "{!Opportunity.Id}";
       object.Record_View_Count__c = {!Opportunity.Record_View_Count__c} + 1;

       var result = sforce.connection.update([object]);
       
       if(result[0].success != 'true'){
           alert('Could not Update the Record View Tracking Information. \r\nError: ' + result[0].errors.message);
       }
   </script>
</apex:page>

(iii) Then go to the Page Layout(say the Oppty for now) > Edit It > Select Visualforce Pages from the Page Host > Drag our new 'RecordViewTracker' on to the Page Layout > Click on the Wedge Icon > Set Height: 0 and Width: 0(so that it is not displayed on the Page).

(iv) Save it.

Working: Whenever someone views the record via the Salesforce UI, then the JavaScript within the In-line Visualforce Page will be executed and the Record View Count on the Oppty record will incremented by 1. Also, you need not put the Record View Count field on the Page Layout.

Now, if you want it on an another Custom Object/Standard Object just do these:

(i) Find and Replace 'Opportunity' with the API Name of that object of concern.
(ii) Make sure you have created the Record View Count field on that Custom Object.
(iii) Drag it to the Page Layout too.

Best,
Deepak
Naveen PeriyasamyNaveen Periyasamy
Thanks Deepak
Deepak AnandDeepak Anand
Hey Naveen,

Happy to help! On which edition are you on ? If it had helped, we can make this a pointer to others too by marking the best one!

Best,
Deepak
Marcel HobizalMarcel Hobizal
This is exactly what I am looking for. Things I need is a log file and who (user) that viewed the record.  Is that possible?
Stacy McdonaldStacy Mcdonald
Deepak - We had implemented what you had suggested (created a VF page that runs on page load that calls an APEX class to log who has viewed and the date)  the problem now is that we are moving to lightning and we are getting a conflict error on page load.  The error tells the end user that another user/process has made changes to the record and cannot proceed.  Has anyone else encountered this and if so what is the work around?
Marcel HobizalMarcel Hobizal
Stacy - did this code log the user also?  
Stacy McdonaldStacy Mcdonald
yes we are referencing a field off of the logged in user
Marcel HobizalMarcel Hobizal
Thank you!
Sara BurchSara Burch
Stacy Mcdonald- How did you incorporate the logged in user?
Piyush SinghalPiyush Singhal
While using Salesforce Field History tracking feature for auditing field value updates, sometimes the 20 field limit applied by Salesforce can be challenging.  If you had a reason to add 2 more fields needed by your organization business need, you will have to prioritize out of the given 22 which are the highest so you have to choose the most important ones for tracking and make an unwanted decision.

Kanban Explorer Gives you some unique functionality within Salesforce especially for people who are still thinking to migrate to the Lightning version of Salesforce. Kanban Explorer gives you the power to combine the best of Lightning and Classic providing you with the feature to manage records from a single page, enabling you to manage leads records and opportunities like never before.

From Kanban following stuffs can be achieved: - 
  • Use Lightning feature for the free to Switch. 
  • Manage your records in a single page.
  • Manage your leads, records and all contacts like never before.
  • Change Review all records in one place. 
Discover more by watching the video below
https://www.youtube.com/watch?v=R8778uE8-oo
Download the FREE app from 

https://sforce.co/2t0V436

Feel free to drop me a note in case you need any help.

Piyush