+ Start a Discussion
Abilash Kosigi 8Abilash Kosigi 8 

Difference between Standard List Controller and Standard Set Controller


Can anyone give the  fundamental difference between Standard List Controller & Std Set Controller?
Standard List Controller is a logical term that is used when defining a visualforce page for any objects List Controller, using recordSetVar on <apex:page> in conjunction with StandardController, 

vs. StandardSetController is an Object that refers to these list controllers in Apex Class. 


Roshni RahulRoshni Rahul


From the docs: A Visualforce controller is a set of instructions that specify what happens when a user interacts with the components specified in associated Visualforce markup, such as when a user clicks a button or link. Controllers also provide access to the data that should be displayed in a page, and can modify component behavior.

You can find more information here, but basically a StandardController is for ONE record, i.e. if you'd like to create a new Visualforce page for a single record, you'd use a Standard Controller in your Apex. 


From the docs: Standard list controllers allow you to create Visualforce pages that can display or act on a set of records. Examples of existing Salesforce pages that work with a set of records include list pages, related lists, and mass action pages.

You can find more information here, but basically Set (list) controllers are for MULTIPLE (or a list of) records, i.e. if you'd like to create a new Visualforce page for a List of records (or even from a selection of records on a List view), you'd use a Standard Set Controller in your Apex.
Sagar Nagvekar 29Sagar Nagvekar 29
Difference 1 between Standard List Controller and Standard Set Controller :- (viewState will get hit eventually with Standard List Controller)
Standard List Controller shows all records on 1 page itself. First, Next, Previous, Last links are functioning if clicked, but there are of no use as all the records are anyways shown on 1 page itself. So this is useful if "where" clause is used in the Extension class and some filtering is done on the queried records such that always only few records are to be shown on the VF page and hence, viewState limit of 170 kB won't be hit.
Otherwise after a while viewState limit gets hit (170kB). When too many account records are shown on one page itself.
So ApexPages.StandardSetController is required as it gives setPageSize function. If we set page size to 10, then next 10 records will be visible only after Next button is clicked.
Then First, Next, Previous, Last links/buttons make more sense.
To control the number of records displayed on each page, use a controller extension to set the pageSize and use ApexPages.StandardSetController.

Difference 2 between Standard List Controller and Standard Set Controller :- (blurring of buttons cannot be done with Standard List Controller)
Blurring out of First, Next, Previous, Last buttons cannot be done with Standard List Controller. It can be done with ApexPages.StandardSetController as ApexPages.StandardSetController has variables like hasPrevious and hasNext

Standard List Controller code with extension class (Extension class helps to add "where" clause in the select query) :-
<apex:page standardController="Account" recordSetvar="accounts" extensions="AccountExtension">
  <apex:pageBlock title="Viewing Accounts">
  <apex:form id="theForm">
    <apex:pageBlockSection >
      <apex:pageBlockTable var="a" value="{!accounts}">
        <apex:column value="{!a.name}" title="Acc Name"/>
        <apex:column value="{!a.id}" title="Acc Id"/>
        <apex:column value="{!a.site}" title="Acc site"/>

    <apex:panelGrid columns="2">
      <apex:commandLink action="{!first}">First</apex:commandlink>
      <apex:commandLink action="{!previous}">Previous</apex:commandlink>
      <apex:commandLink action="{!next}">Next</apex:commandlink>
      <apex:commandLink action="{!last}">Last</apex:commandlink>

The extension class :-
public class AccountExtension
    // It is mandatory to provide this constructor which takes parameter of 
    // ApexPages.StandardSetController but it not used as this example 
    // demonstrates Standard List Controller (recordSetVar) 
    public AccountExtension(ApexPages.StandardSetController controller)


    // Specifying this constructor is optional. It is not used as we are not
    // operating on any one specific Account record here. We are viewing all
    // the account records to demonstrate the usage of Standard List Controller (recordSetVar)
    public AccountExtension(ApexPages.StandardController stdController)
    public List<Account> accounts;
    public List<Account> getAccounts()
        accounts = [Select id, name, site from Account where name like 'Edge%'];
        return accounts;