Hi my friends, In this tutorial, we are going to understand the use of the Standard List Controller in Visualforce Page Salesforce. Standard list controller makes it easy to display a list of records for a specific object. We don’t need to write any line of code for displaying a list of data.

Standard List Controller in Visualforce Page:

Displaying a list of record in tabular format is common requirements for any web application. Standard list controller makes it easy to display a list of records for a specific object. We don’t need to write any line of code for displaying a list of data. For using a Standard List Controller the following attributes need to add at

<apex:page>.

 standardController="objectname"
 recordSetVar="variable-name"

Example of setting Standard List Controller:

<apex:page standardController="Contact" recordSetVar="contacts"></apex:page>

where recordSetVar sets the name of the variable to be which holds the collection of records for an object.

To display records in a table I am using <apex:pageBlockTable> which is an iteration component that generates a table for the data.
Syntax for declaring <apex:pageBlockTable> for display list data:

<apex:pageBlockTable value="{!contacts}" var="contact></apex:pageBlockTable>

Where, value=”{!contacts}” holds the variable name that is loaded by the standard list controller by using recordSetVar attribute and var holds the each item of the collection.
<apex:column> uses the field to create column headers, by looking up the label for each field.

for example:

<apex:column value="{!contact.Name}"/>

<apex:column> component must be inside the <apex:pageBlockTable> component.

A complete example of using Standard list controller:

<apex:page standardController="Contact" recordSetVar="contacts">
<apex:pageBlock title="Account List">
<apex:pageBlockTable value="{! contacts}" var="contact">
<apex:column value="{!contact.Name}"/>
<apex:column value="{!contact.Email}"/>
<apex:column value="{!contact.Phone}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:page>

Output:

Standard List

View More:

Conclusion:

I hope you loved this post. Please feel free to comment for any technical issues. Your feedback and suggestions would be appreciated.

Thank You.

Leave a Comment