I have created the Visualforce Page,I am giving the page access to all users such as System administrator user and internal users,I have created two new custom fields in account object such as Last Viewed user and count of the particular user
If sys administartor user view the page then the account object of the record,last Viewed user as sys administrator name and count will be 1,now another internal user viewing the page then last viewed user as internaluser name and now also count will be 1, because that particular user viewing the page now only,so his count will be 1
How to take the count Value for particular user and user name and how to store the value in Record of Account Object,Please Anyone Guide me for the Answer using Visual force and apex class
I have Tried:
Apex class:
public class DisplayPage {
public Decimal ViewCount {get; set;}
public DisplayPage(ApexPages.StandardController Controller) {
this.ViewCount = 0;
TotalRecordUpdate();
}
public void TotalRecordUpdate(){
Id profileId = UserInfo.getProfileId();
List<Page_View__c> pageViews = [SELECT Id, Count__c,AddsName_c__c FROM Page_View__c WHERE AddsName_c__c = :profileId ];
// system.debug(AddsName_c__c);
system.debug(pageViews);
system.debug(profileId);
if(pageViews.size() == 0){
Page_View__c pageView = new Page_View__c(Count__c = 1, AddsName_c__c = profileId);
system.debug(pageView);
this.ViewCount = 1;
}else{
pageViews[0].Count__c += 1;
this.ViewCount = pageViews[0].Count__c;
update pageViews[0];
}
}
}
Visual Force Page:
<apex:page standardController="Account" extensions="Displaypage" action="{!updateCount}">
<apex:form >
<apex:actionFunction name="updateCount" action="{!updateCount}" reRender="" />
<script>
addEventListener("load", updateCount, false);
</script>
</apex:form>
</apex:page>
But it is Not working? Please anyone Share the Logic and Answer