function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
B2000B2000 

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 
    {
        get
        {
            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())
                	system.debug('\n\n@@@ao[PRE]='+ao);
                	
				setCon.setPageSize(size);				
                listViewOptions 	= setCon.getListViewOptions();                        		
        		setCon.setFilterID(listViewOptions[0].getValue());
        		if (filterId != null)
        			setCon.setFilterID(filterId);        		
                noOfRecords 		= setCon.getResultSize();
                system.debug('\n\ngetFilterId='+setCon.getFilterId());
                for (Affiliate_Order__c ao :(List<Affiliate_Order__c>)setCon.getRecords())
                	system.debug('\n\n@@@ao[POST]='+ao);
                
        		
            }
            return setCon;
        }
        set;
    }
     
    public List<Affiliate_Order__c> AOList
    {
    	get 
    	{
    		
	        Affiliate_Order__c[] AOList 	= new Affiliate_Order__c[]{};
	        for (Affiliate_Order__c ao :(List<Affiliate_Order__c>)setCon.getRecords())
	        {
	        	AOList.add(ao);
	        }

	        return AOList;
    	}
    	set;
    }
     
    public pageReference refresh() 
    {
        setCon 						= null;
        setCon.setPageNumber(1); 
        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:selectList>   
            </apex:pageBlockButtons>
            
            <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>
                <apex:column headerValue="Created">
                    <apex:outputText value="{0,Date,M/d/yyyy}" >
                        <apex:param value="{!ao.createdDate}"/> 
                    </apex:outputText>        
                </apex:column>    
            </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="{!refreshList}" 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>