function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

A field to capture who is currently viewing a record

Is there a way to capture which users are currently viewing a record? We want to make use of the console view but don't want users accessing a record if another user is already viewing it.
Rahul KumarRahul Kumar (Salesforce Developers) 
Hi Rang41,

solution 1:
You can do this by a custom solution:

(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="Case">
   <apex:includeScript value="/soap/ajax/28.0/connection.js"/>
   <script type="text/javascript">
       sforce.connection.sessionId = '{!GETSESSIONID()}';

       var object = new sforce.SObject('Case');
       object.Id = "{!Case.Id}";
       object.Record_View_Count__c = {!Case.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);

(iii) Then go to the Page Layout(say the Cases 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 increment 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 'Case' 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.

Solution 2:

Please check the Below link for reference.
Please mark it as best Answer if it resolved the issue.
Thank you for the feedback and the code!! After implanting the code the “Record View Count” value goes up incrementally for each page view. Is there way to remove the incremental increase, and just flag the record when a user(s) is viewing a record, and then flag when the record is not currently being access? For example, update the value to 1 if a user(s) are viewing the record, and then update the value to 0 if no user(s) are viewing the record. Best regards, Robert Rung| Business Analyst / Salesforce Admin Brook Furniture Rental | P: 847.810.4038 | M: 847.220.2588 | E: