You need to sign in to do that
Don't have an account?
Sunay - 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.
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
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.
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
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.
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
But how is the blank page opened everytime to run that class???
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.
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.