I'm looking to create a VF page with a list of records and dynamic filter criteria. The user needs to be able to filter the records based on various criteria and also save those filters for future use. They also need to be able to select certain records via checkboxes and perform an action (creating other records).

Before I launch into a full custom page would there be any advantage to leveraging Standard Set Controllers or any of the list view apex tags to support this? I'm not performing a bulk update to these records I'm just creating new ones based on them so I'm not sure Standard Set Controllers are that helpful but I've just learned about them.

Also, could I leverage the Objects list views as filter criteria and programatically create new list views?


1 Answer 1


Yes you can leverage user defined List Views programatically via the StandardSetController. In two ways, one is utilising the one the platform creates for you or by creating an instance of this class yourself.

Take a look at these questions and answers for examples StandardSetController List Instatiation and setFilterId. Also this one around Custom Buttons that can sit on the standard List View UI and provide a check box UI for free, which is the most common way to use them Creating a custom list-view button that handles multi-record selection.

If you need more flexibility, as mentioned in one of the referenced questions above, you can choose to create your own instance, it's quite an advanced usage though, so consider the Custom Button route first. Here is a code example where you can set the List View (via setFilterId) and effectively reuse the criteria the user has setup using the standard List View UI. A great example of going native on the platform!

string SOQL = 'SELECT Id, Name, Phone FROM Account Order By Name DESC';
List<Account> accounts = Database.query(SOQL);
for(Account account : accounts)
    System.debug(account.Name + ', Phone: ' + account.Phone);
ApexPages.StandardSetController ssc = 
     new ApexPages.StandardSetController(Database.getquerylocator(SOQL)); 
ssc.setFilterId('00BG000000702tj'); // 'Platinum and Gold SLA Customers'
for(Account account : (List<Account>) ssc.getRecords())
    System.debug(account.Name + ', Phone: ' + account.Phone);

Note: You can enumerate the List View's names and Id's to present a choice to the user or find one you've packaged via getListViewOptions().

Hope this helps, give you some food for thought!

  • Awesome thanks its a lot to digest. I'm moving forward with my own instance of the StandardSetController. Is it possible to wrap the records returned in a wrapper class and maintain the checkbox across pagination? Also, my getListViewOptions() is only returning 'All' any suggestions? I can start a new question if you'd prefer. Thanks for the help!
    – Phil B
    Jun 5, 2013 at 21:32
  • Glad to be of service! As regards a wrapper class, yes this is possible, take a look at this wiki.developerforce.com/page/Wrapper_Class. As regards seeing only All, are the other list views marked as visible to all users perhaps? Jun 5, 2013 at 22:18

You must log in to answer this question.

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