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
hramanihramani 

How Do I display the total count of records (of an object, could be custom or standard) on a VF using a Custom Controller.


When the VF loads, I want the page to display the total record count.  
e.g. Assuming App_Process__c is a Custom Object:
VF Page load result:

Total Number of App Forms : 200

Can someone help me with a simple example.
Khan AnasKhan Anas (Salesforce Developers) 
Hi,

Greetings to you!

Below is the sample code which I have tested in my org and it is working fine. Kindly modify the code as per your requirement.

Visualforce:
<apex:page controller="CountRecordsC">
    Total Records : <apex:outputText value="{!total}"/>
</apex:page>

Controller:
public class CountRecordsC {
    
    public Integer total;
    
    public Integer getTotal() {
        total = [SELECT count() FROM Account]; // Example for standard Account objects
        return total;
    }
}

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas