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
Sunay - KVP Bus SolnsSunay - KVP Bus Solns 

Time tracker to check the number of times a particular record is opened

Hi,

 

We are planning to build a functionality where we need to have a report to check the number of times a record is viewed on the Account object. 

 

I need to build a apex code which will capture the number of times a record is opened. Can anybody help or suggest me how can I achieve this. 

 

Would appreciate any help regarding this as it is critical.

 

 

Best Answer chosen by Admin (Salesforce Developers) 
Gunners_23Gunners_23

Exactly !!!... We have do any DML operations using Controller or based on any event like button click (in this case we don't want

 

that) , so for that we can use a Blank VF page with a controller. The controller as you said previously is used to update in

 

backend 

 

For ex :

 

Blank VF page

 

<apex:page standardController="" Extensions="UpdateStatus" action="{!init}" showHeader="false" sidebar="false">
</apex:page>

 

UpdateStatus Controller

 

public class UpdateTaskStatus{
    public UpdateTaskStatus(ApexPages.StandardController controller){
        //nothing   
    }
    
    public void init(){
        // Get the record by  querying which is currently being accessed( may be by passing id of record)
        count ++ ;
        //update record
    }
}

 

Cheers

 

All Answers

stcforcestcforce

not an expert (kinda new to apex etc) but possibly create a field on the record to store the value, override the view page (with a visualforce page/controller), so that the underlying visualforce controller increments the field value as stored on the record each time page is opened. just a guess.

Gunners_23Gunners_23

Create a field in that object to store the count

 

In the view Page add one blank VF page and in action call the controller which will update the count

 

 

Cheers

Sunay - KVP Bus SolnsSunay - KVP Bus Solns

Can you tell in detail..Because I dont understand what will the blank VF page do...Do you mean to say everytime they click on the record the visual force page is opened and the field is updated in the back end. 

 

Im in a confsuion, can you please elaborate.

 

 

Gunners_23Gunners_23

Exactly !!!... We have do any DML operations using Controller or based on any event like button click (in this case we don't want

 

that) , so for that we can use a Blank VF page with a controller. The controller as you said previously is used to update in

 

backend 

 

For ex :

 

Blank VF page

 

<apex:page standardController="" Extensions="UpdateStatus" action="{!init}" showHeader="false" sidebar="false">
</apex:page>

 

UpdateStatus Controller

 

public class UpdateTaskStatus{
    public UpdateTaskStatus(ApexPages.StandardController controller){
        //nothing   
    }
    
    public void init(){
        // Get the record by  querying which is currently being accessed( may be by passing id of record)
        count ++ ;
        //update record
    }
}

 

Cheers

 

This was selected as the best answer
Sunay - KVP Bus SolnsSunay - KVP Bus Solns

But how is the blank page opened everytime to run that class??? 

Gunners_23Gunners_23

Blank page will be placed in the Page Layout ( since standardController should be mentioned inorder that page to be appear

 

in  Pagelayout i've specified that). So whenever a user views the detail page, the blank page will be loaded (inline VF)

 

,although inivisble for users along with the other fields and sections in detail page and after loading action method of the

 

Blank VF page will be called which will update the record access count.

 

 

 

Sunay - KVP Bus SolnsSunay - KVP Bus Solns

Ok I understood. But I am getting a error which says coun variable does not exist. By what value the field has to be updated?? I mean should I use a javascript to update that field everytime.