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
Vithal SindigarVithal Sindigar 

I need to have a code which counts the no of times the record has been accessed , please give logic

hi all ,

need to have a code which counts the no of times the record has been accessed , please give logic or code I need to complete 

Thanks
Best Answer chosen by Vithal Sindigar
Manj_SFDCManj_SFDC
Hi please refer

https://salesforcemonk.wordpress.com/2018/03/20/record-visit-counter/

All Answers

Manj_SFDCManj_SFDC
Hi please refer

https://salesforcemonk.wordpress.com/2018/03/20/record-visit-counter/
This was selected as the best answer
Manj_SFDCManj_SFDC
VF Page:
<apex:page extensions="StandardControllerExtension" action="{!updateCounter}" showheader="false" sidebar="false" standardcontroller="Account"></apex:page>
Add this page to the Account page layout
Controller:
public class StandardControllerExtension {
List<Account> accList;
@TestVisible
Id accID;
private final Account acct;
public StandardControllerExtension(ApexPages.standardController stdController){                acct = (Account)stdController.getRecord();
accId = acct.Id;
}
public void updateCounter(){
accList = [SELECT Id, Record_Visit_Counter__c FROM ACCOUNT WHERE Id = :accID];
for(Account a : accList){
a.Record_Visit_Counter__c += 1;
}
update accList;
}
}