Recently, one of our Minneapolis Salesforce clients had the requirement to track how “popular” records were by looking at how many times users had accessed them via the Web UI.  At first we thought this might not be possible, especially with clicks not code, but stumbled on this great answer by Deepak Anand:

He details the steps in that link, but we wanted to recreate the process below.  The general solution is to create a Visualforce page that is then added to the page layout with a Height and Width of 0 (so it is essentially hidden from view).  This Visualforce page then updates a custom Number field on the Salesforce record with a view count.  Check out the steps below to see if this will work for your Salesforce org!


1. Create a custom Number field (18, 0) on your object (we’re using the Opportunity in this example) called “View Count”.2. Go to Setup > Develop > Pages and create the following Visualforce Page.

Label: View Tracker
Name: ViewTracker

<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.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);

3. Edit the Opportunity Page Layout, select Visualforce Pages, add ‘ViewTracker’ anywhere on the layout, click the Wedge Icon and set Height: 0 and Width: 0 (this hides the Visualforce page from the layout).

Working: Now whenever someone views the record in the Salesforce UI, the JavaScript in our hidden Visualforce component will run and the Record View Count on the Opportunity record will increase by 1.

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

1. Create the View Count field on your Custom Object.
2. Find and replace ‘Opportunity’ in the code above with the API Name of your custom object.
3. Drag it to the Page Layout too.


Please feel free to reach out with any questions about this process!

Leave a Reply

Your email address will not be published. Required fields are marked *