+ Start a Discussion
N@niN@ni 

what is StandardSetController ????????

I am new to salesforce, I want to Know

 

what is the use of  standardsetcontroller??????

 

can you give me manual explanation, I am not able to understanding salesforce documents....

 

please help me....

 

 

Thanks In Advance.

 

 

Sonam_SFDCSonam_SFDC

Standard controller is used when you wish to use your custom UI built using visualforce but want to implement the standard functions of new, save, edit, close etc without any customizations

 

 

N@niN@ni

Thanks for ur Reply,,

 

I am asking what is standardsetcontroller???? Not standardcontroller.

 

 

Prady01Prady01

Hi there, Check this out.

 

StandardSetController allow you to create list controllers.

 

Link for further details: http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_pages_standardsetcontroller.htm

 

Hope it helps!

Prady

 

 

souvik9086souvik9086

StandardSetController allows us to create list controllers similar to, or as extensions of, the pre-built Visualforce list controllers provided by Salesforce

 

For e.g when you want to override a tab or list view with your custom visualforce page like

 

Page

<apex:page standardController="Account" recordsetvar="Accounts extension="AccListController">

<apex:pageBlock>
<apex:pageBlockTable value="{!accountList}" var="o">
<apex:column value="{!o.Name}"/>
<apex:column value="{!o.Amount}"/>
</apex:pageBlockTable>
</apex:pageBlock>

</apex:page>

 

Controller

public class AccListController{
// ApexPages.StandardSetController must be instantiated
// for standard list controllers
public ApexPages.StandardSetController setCon {
get {
if(setCon == null) {
setCon = new ApexPages.StandardSetController(Database.getQueryLocator(
[SELECT Name, Amount FROM Account]));
}
return setCon;
}
set;
}

// Initialize setCon and return a list of records
public List<Account> getAccountList() {
return (List<Account>) setCon.getRecords();
}
}

 

 

souvik9086souvik9086

Another type of example is like this

 

Page

<apex:page standardController="Account" recordsetvar="Accounts extension="AccListController">

<apex:pageBlock>
<apex:pageBlockTable value="{!accountList}" var="o">
<apex:column value="{!o.Name}"/>
<apex:column value="{!o.Amount}"/>
</apex:pageBlockTable>
</apex:pageBlock>

</apex:page>

 

Controller

public class AccListController{
public List<Account> accountList{get;set;}
public AccListController(ApexPages.StandardSetController setCon) {
accountList = new List<Account>();
Map<Id,SObject> accMap = new Map<Id, SObject>(setCon.getSelected());
accountList = [SELECT ID, Name FROM Account where ID IN :accMap.keyset()];
System.debug('###setCon.getrecords()###'+setCon.getrecords());
}
}

 

To test this you have to create a Button from which you call your Visualforce page in the List view of Account and select the accounts you want to get and call that button.

 

If the post helps you please throw KUDOS.

Thanks

Sagar Nagvekar 14Sagar Nagvekar 14
StandardSetController returns a list of records by executing a SOQL query. The benefit it has over simply a list is that it provides a lot of inbuilt methods like next(), getHasNext() which makes implementing pagination easier.
Sagar Nagvekar 14Sagar Nagvekar 14
Both standard list controllers and StandardSetController provide inbuilt pagination mechanism.
But standard list controllers returns records using inbuilt SOQL only. If custom query is to be used with ORDER BY etc. clause, then StandardSetController will have to be used to make use of inbuilt pagination mechanism also.
Example of standard list controller with pagination :-
<apex:page standardController="Account" recordSetVar="Accounts" sidebar="false" >
<apex:sectionHeader title="My Accounts" subtitle="Account Management"/>
    <apex:form >
        <apex:pageBlock >
          <apex:pageMessages id="error" />
            <apex:panelGrid columns="7" id="buttons">
                <apex:commandButton reRender="error,blocktable,buttons" action="{!Save}" value="Save"/>
                <apex:commandButton reRender="error,blocktable,buttons" action="{!Cancel}" value="Cancel"/>
                <apex:inputHidden />
                <apex:commandButton reRender="error,blocktable,buttons" disabled="{!!hasprevious}" action="{!First}" value="First"/>
                <apex:commandButton reRender="error,blocktable,buttons" disabled="{!!hasprevious}" action="{!Previous}" value="Previous"/>
                <apex:commandButton reRender="error,blocktable,buttons" disabled="{!!hasnext}" action="{!Next}" value="Next"/>
                <apex:commandButton reRender="error,blocktable,buttons" disabled="{!!hasnext}" action="{!Last}" value="Last"/>
            </apex:panelGrid>
            <apex:pageBlockSection id="blocktable" >
                <apex:pageBlockTable value="{!Accounts}" var="t">
                    <apex:column headerValue="Account" value="{!t.Name}" />
                  
                    <apex:column headerValue="Site">
                        <apex:outputField value="{!t.site}" />
                    </apex:column>
                    <apex:inlineEditSupport event="onClick"/>
                </apex:pageBlockTable>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>
Example of StandardSetController with pagination :-
public with sharing class PaginationExtension {
    Public Integer noOfRecords{get; set;}
    Public Integer size{get;set;}
    public ApexPages.StandardSetController setCon {
        get{
            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));
                setCon.setPageSize(size);
                noOfRecords = setCon.getResultSize();
            }
            return setCon;
        }set;
    }
   
    Public List<Account> getAccounts()
    {
        List<Account> accList = new List<Account>();
        for(Account a : (List<Account>)setCon.getRecords())
            accList.add(a);
        return accList;
    }
   
    public pageReference refresh() {
        setCon = null;
        getAccounts();
        setCon.setPageNumber(1);
        return null;
    }
}
VF page:
<apex:page Controller="PaginationExtension">
    <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:pageBlockTable>
            <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=""/>
                </apex:outputPanel>
            </apex:panelGrid>
        </apex:pageBlock>
    </apex:form>
</apex:page>
 
Shubham Agrawal 22Shubham Agrawal 22
Hi,

ApexPages.StandardController  (documentation) encapsulates just a single Sobject (e.g. Account, Opportunity).
ApexPages.StandardSetController (documentation) contains a list of records (one or more), and has additional functions to facilitate pagination (moving between pages) and updating a number of records at once.

For example in test class when we initialize,
ApexPages.StandardController
Account objAccount = [SELECT Name FROM Account LIMIT 1];
ApexPages.StandardController standctrl = new ApexPages.StandardController(objAccount );

ApexPages.StandardSetController
List<account> accountList = [SELECT Name FROM Account LIMIT 20]; ApexPages.StandardSetController ssc = new ApexPages.StandardSetController(accountList);

That means using StandardSerController you can deisgn List controllers.

https://salesforce.stackexchange.com/questions/112380/diffrence-between-standardcontroller-and-standardsetcontroller