I'm having an issue using a List to instantiate the StandardSetController and applying a list view filter id.

Here's an example of using a List for instantiation as detailed at http://www.salesforce.com/us/developer/docs/pages/Content/apex_pages_standardsetcontroller.htm

        List<Campaign> campaigns = [SELECT Id FROM Campaign LIMIT 10000];
        ApexPages.StandardSetController ssc = new ApexPages.StandardSetController(campaigns);
        system.debug('standard set controller count before filter: '+ssc.getResultSize());
        system.debug('standard set controller count after filter: '+ssc.getResultSize());

The result of this is:

18:12:09:176 USER_DEBUG [17]|DEBUG|standard set controller count before filter: 10000
18:12:09:177 USER_DEBUG [19]|DEBUG|00BU0000002L6POMA0
18:12:09:177 USER_DEBUG [20]|DEBUG|standard set controller count after filter: 10000

'00BU0000002L6POMA0' is the id of a valid list view filter that should return two results according to the UI as well as my investigation in the org.

However, the filter is appropriately applied if I use the queryLocator method of instantiation.

        ApexPages.StandardSetController ssc = new ApexPages.StandardSetController(Database.getQueryLocator([SELECT Id FROM Campaign LIMIT 10000]));
        system.debug('standard set controller count before filter: '+ssc.getResultSize());
        system.debug('standard set controller count after filter: '+ssc.getResultSize());

results in:

18:17:37:233 USER_DEBUG [17]|DEBUG|standard set controller count before filter: 10000
18:17:37:319 USER_DEBUG [19]|DEBUG|00BU0000002L6POMA0
18:17:37:319 USER_DEBUG [20]|DEBUG|standard set controller count after filter: 2

Has anyone seen this and overcome it somehow?

The reason I would like to use the List instantiation is that it gets me around the nasty "Too many query locator rows: 10001" when I loop the StandardSetController instantiation a couple times to boost the # of records I can filter and return.

  • Just a guess, but I'd say it's because using a query locator it can add filter logic as it needs to and re-run the query. Using a list it'd have to filter the data loaded, but it's only got ID to work with. Maybe add the filtered fields to the query to see if that makes a difference, but I doubt it will.
    – Matt Lacey
    Oct 22, 2012 at 3:03
  • 1
    No change if I add all fields to the query being pulled into the list. Good thought though, thanks for the comment. Oct 22, 2012 at 3:24
  • Are you trying to show the list in the page? If so, you can show only 1000(if editable) or 10000(in a read only mode). Oct 22, 2012 at 10:51
  • 1
    Hi Vignesh, at this point I am just attempting to use multiple instances of the standard set controller to filter >10k records by a list view. If I use the list instantiation method I can filter 50k (the SOQL result row limit), then create a pagination method. Unfortunately the query locator method is governor limited to 10k rows. Another possible solution to this would be the elusive describe method to find the parameters of a list view filter, and then build up a soql query which filters without the need for a standard set controller. Oct 22, 2012 at 13:10

1 Answer 1


I think utilising the List View UI to allow your users to reuse this part of the platform is a great design decision btw! I've used this approach before and can tell you it does not matter what the original record set you select with your query selector is, so you can in fact use LIMIT 1.

However, unfortunately the StandardSetController will only handle 10,000 rows regardless, check out the documentation for the StandardSetController.getCompleteResult method.

"Indicates whether there are more records in the set than the maximum record limit. If this is false, there are more records than you can process using the list controller. The maximum record limit is 10,000 records."

So at least this method does let you inform the users that the results your showing them are truncated and thus ask them to refine their selection criteria.

If thats not going to be good enough for them or you, then you could utilise the Metadata API to retrieve the ListView definition and roll your own SOQL query. I've recently done this in Java for a DF12 presentation here. If you want to do this in Apex you can also utilise the Apex Metadata API library here. Let me know if you want to this route we could build a sample here together.

  • 1
    Andrew, this is by far the best answer I have seen for this particular struggle. I am going to look at using the metadata api library you linkedto roll my own SOQL. Thank you for the insight and the offer to assist in the implementation! I will be in touch! Oct 24, 2012 at 3:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .