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
Nagaraju Mogili 15Nagaraju Mogili 15 

how can we display the list of accounts using the controller and visualforce page

Dev_AryaDev_Arya
you can have a function in your controller to get the list of sObject records. And using apex pageblocktable you can display those records in your visualforce page.
This may help:
https://help.salesforce.com/articleView?id=000205631&type=1
https://trailhead.salesforce.com/en/modules/visualforce_fundamentals/units/visualforce_output_components

Cheers,Dev
Maharajan CMaharajan C
Hi,

VF Page:

<apex:page controller="StandardAccountDisplayController"> 
    <apex:pageBlock title="Account List"> 
        <apex:pageBlockTable value="{!records}" var="record"> 
            <apex:column > 
                <apex:facet name="header">Account Name</apex:facet> 
                <apex:outputText value="{!record.Name}"/> 
            </apex:column> 
            <apex:column > 
                <apex:facet name="header">Account Number</apex:facet> 
                <apex:outputText value="{!record.AccountNumber}"/> 
            </apex:column> 
            <apex:column > 
                <apex:facet name="header">Phone</apex:facet> 
                <apex:outputText value="{!record.Phone}"/> 
            </apex:column> 
            <apex:column > 
                <apex:facet name="header">Account Industry</apex:facet> 
                <apex:outputText value="{!record.Industry}"/> 
            </apex:column> 
        </apex:pageBlockTable> 
    </apex:pageBlock> 
</apex:page>

Controller:

public with sharing class StandardAccountDisplayController{ 
public List<Account> records {get; set;} 
public StandardAccountDisplayController(){ 
records = [select Name, AccountNumber , Phone, Industry from Account]; 

}

Can you please Let me know if it works or not!!!

If it helps don't forget to mark this as a best answer!!!


Thanks,
​Raj