+ Start a Discussion

StandardSetController with List View

I am trying to use a StandardSetController with a sorted List View.  Instantiating the StandardSetController using a List of objects provides a different set of records than instantiating using a query locator when followed by using the 

setFilterID method.  I've tried sorting using the inital query and also sorting using a column in the List View. 


Case 1: Query Locator.  

  A. Records from query locator are sorted correctly after the query.

  B. Records are resorted after setting the setFilterId by the Name field and not by either the initial query nor by the sorted field selected on the List View (I've tried several different columns on the List View and moving the columns to the first item too)

  C. Changing the picklist listViewOptions value, filterId, correctly changes the records returned in step B from the correct List View.  But again the records are not sorted correctly by either the query in step A nor the sorted field selected in the List View.


Case 2: List of Objects:

  A. Records from query locator are sorted correctly after the query.

  B. Records remain sorted correctly after setting the setFilterId.  

  C. Changing the picklist listViewOptions value, filterId, does not change the records returned in step B. It appears in step B the setFilterId is not being applied. So the records are from the orginal query and the List View filters is not being applied.


    public ApexPages.StandardSetController setCon 
            if(setCon == null)
            	Affiliate_Order__c[] qryList = [SELECT Name, createdDate
                	FROM Affiliate_Order__c order by createdDate DESC Limit 10000];
                size = 20;
                string queryString 	= 'SELECT Name, createdDate FROM Affiliate_Order__c order by createdDate DESC Limit 10000';
				setCon = new ApexPages.StandardSetController(qryList);               
                //setCon = new ApexPages.StandardSetController(Database.getQueryLocator(queryString));
                for (Affiliate_Order__c ao :(List<Affiliate_Order__c>)setCon.getRecords())
                listViewOptions 	= setCon.getListViewOptions();                        		
        		if (filterId != null)
                noOfRecords 		= setCon.getResultSize();
                for (Affiliate_Order__c ao :(List<Affiliate_Order__c>)setCon.getRecords())
            return setCon;
    public List<Affiliate_Order__c> AOList
	        Affiliate_Order__c[] AOList 	= new Affiliate_Order__c[]{};
	        for (Affiliate_Order__c ao :(List<Affiliate_Order__c>)setCon.getRecords())

	        return AOList;
    public pageReference refresh() 
        setCon 						= null;
        return null;
    public void refreshList(){}

<apex:page controller="AffiliateOrderTabExt" sidebar="false">
    <apex:form >
        <apex:pageBlock id="pb" title="Orders">
            <apex:pageMessages />
            <apex:actionFunction name="refresh" action="{!refresh}" reRender="pb"/>
            <apex:pageBlockButtons location="top">
                    <apex:outputLabel value="View:" style="font-weight:bold;"/>&nbsp;&nbsp;
                    <apex:selectList value="{!filterId}" size="1">
                        <apex:actionSupport event="onchange" action="{!refresh}" reRender="pb" />
                        <apex:selectOptions value="{!listViewOptions}"/>
            <apex:pageBlockTable value="{!AOList}" var="ao" id="aoTable">

                <apex:column headerValue="Order">
                    <apex:outputLink value="{!URLFOR($Page.AffiliateOrderViewPage,null,['aoId'=ao.id])}">{!ao.Name}</apex:outputLink>
                <apex:column headerValue="Created">
                    <apex:outputText value="{0,Date,M/d/yyyy}" >
                        <apex:param value="{!ao.createdDate}"/> 
            <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="{!refreshList}" title="Refresh Page"/>
                <apex:outputPanel style="color:#4AA02C;font-weight:bold">
                    <apex:actionStatus id="fetchStatus" startText="Fetching..." stopText=""/>