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
Jordan@BracketLabsJordan@BracketLabs 

StandardSetController doesn't use ORDER BY or Respect FilterId

I've discovered that when using the following object I get some strange behavior, and I'm wondering if anyone can point out what I'm doing wrong??

 

The following setup returns the campaigns list correctly filtered by the paramters in the associated FilterId for the 'Campaign' object but the orderby clause is invalidated and the campaigns are sorted by the 'last selection on the standard list view vf component' under the default campaigns tab, so ordered by 'Name' or 'Type' or whatever...not 'StartDate ASC' as set.

ApexPages.StandardSetController ssc = new ApexPages.StandardSetController(Database.getQueryLocator([SELECT Id, Name, StartDate, EndDate, Type, Status, Description, Owner.Name,NumberOfLeads, NumberOfContacts, NumberOfOpportunities, NumberOfWonOpportunities,AmountAllOpportunities, Exclude_from_Calendar__c FROM Campaign ORDER BY StartDate ASC]));
ssc.setFilterID(this.filterId);
ssc.setPageSize(2000);
// use standardset controller to limit results by listview
List <Campaign> campaignObjects = ssc.getRecords();	

 The following setup returns the campaigns list correctly sorted using the ORDER BY clause, but they are not FILTERED by the associated listview filterid using 'setFilterId('...')'

List<Campaign> campaigns = [SELECT Id, Name, StartDate, EndDate, Type, Status, Description, Owner.Name,NumberOfLeads, NumberOfContacts, NumberOfOpportunities, NumberOfWonOpportunities,AmountAllOpportunities, Exclude_from_Calendar__c FROM Campaign ORDER BY StartDate ASC];
ApexPages.StandardSetController ssc = new ApexPages.StandardSetController(campaigns);
ssc.setFilterID(this.filterId);
ssc.setPageSize(2000);
// use standardset controller to limit results by listview
List <Campaign> campaignObjects = ssc.getRecords();	

 

What am I missing about ordering these campaigns correctly...

pranav prashant 10pranav prashant 10
I stuck at this too.
Anjum Attar 26Anjum Attar 26
@jordan Can you please send your VF page and Controller code So, I can try out using that code