+ Start a Discussion

what is standardsetcontroller??????????

What is the main use of stadardsetcontroller???

It has two primary uses: (1) to display a paginated list of records from a query containing up to 2,000 rows, and (2) to allow mass inline editing of those records or some subset (via "selected records"). To facilitate both functions, it allows a developer to use an existing list view that can be exposed directly in Visualforce as a drop-down, and has a "prototype" object that will set all selected records' fields to the same value as the prototype when the save function is called on the StandardSetController. I'd advise reading the documentation, it should be fairly self-explanatory.
Grazitti InteractiveGrazitti Interactive



Uses of StandardSetController:-

      1. Pagination

       2.  Useful for writing pages that perform mass updates (applying identical changes to fields within a collection of                  objects).




As the number of records increases, the time required for the browser to render them increases. Paging is used to reduce the amount of data exchanged with the client. Paging is typically handled on the server side (standardsetcontroller). The page sends parameters to the controller, which the controller needs to interpret and then respond with the appropriate data set.




Here is the controller which makes use of standard set controller for pagination


public with sharing class Pagination_min {
    Public Integer noOfRecords{get; set;}
    Public Integer size{get;set;}
    public ApexPages.StandardSetController setCon {
            if(setCon == null){
                size = 10;
                string queryString = 'Select Name, Type, BillingCity, BillingState, BillingCountry from Account order by Name';
                setCon = new ApexPages.StandardSetController(Database.getQueryLocator(queryString));
                noOfRecords = setCon.getResultSize();
            return setCon;
    Public List<Account> getAccounts(){
        List<Account> accList = new List<Account>();
        for(Account a : (List<Account>)setCon.getRecords())
        return accList;
    public pageReference refresh() {
        setCon = null;
        return null;


/**Using the above controller methods we can define the pagination.**/

<apex:page controller="Pagination_min">
    <apex:form >
        <apex:pageBlock id="pb">
            <apex:pageBlockTable value="{!Accounts}" var="a">
                <apex:column value="{!a.Name}"/>
                <apex:column value="{!a.Type}"/>
                <apex:column value="{!a.BillingCity}"/>
                <apex:column value="{!a.BillingState}"/>
                <apex:column value="{!a.BillingCountry}"/>
            <apex:panelGrid columns="7">
                <apex:commandButton status="fetchStatus" reRender="pb" value="|<" action="{!setCon.first}" disabled="{!!setCon.hasPrevious}" title="First Page"/>
                <apex:commandButton status="fetchStatus" reRender="pb" value="<" action="{!setCon.previous}" disabled="{!!setCon.hasPrevious}" title="Previous Page"/>
                <apex:commandButton status="fetchStatus" reRender="pb" value=">" action="{!setCon.next}" disabled="{!!setCon.hasNext}" title="Next Page"/>
                <apex:commandButton status="fetchStatus" reRender="pb" value=">|" action="{!setCon.last}" disabled="{!!setCon.hasNext}" title="Last Page"/>
                <apex:outputText >{!(setCon.pageNumber * size)+1-size}-{!IF((setCon.pageNumber * size)>noOfRecords, noOfRecords,(setCon.pageNumber * size))} of {!noOfRecords}</apex:outputText>
                <apex:commandButton status="fetchStatus" reRender="pb" value="Refresh" action="{!refresh}" title="Refresh Page"/>
                <apex:outputPanel style="color:#4AA02C;font-weight:bold">
                    <apex:actionStatus id="fetchStatus" startText="Fetching..." stopText=""/>
For more information go through following links
If this post helps you than please mark it as a solution and don't forget to give me kudo's.