How to access ListView in Apex | Using StandardSetController for Pagination

There are scenario in project lifecycle where developer creates SOQL or Dynamic SOQL to return expected result. Also if requirement changes they go back and change existing code to reflect updated SOQL. If you are good developer and avoid to change Apex code at most you will save your SOQL in “Custom Settings” and utilize in Dynamic SOQL.

However, There is very good design Developer can suggest to client. Instead of going to your code and changing code for new requirement, how it sounds if we can utilize existing List View inside Apex or Visualforce only 🙂 ? It will solve lots of problems and if requirement changed, just change or create new Listview and it will reflect in your Visualforce code. We can almost have same functionality like Navigation buttons and Paging without writing any complex code logic, thanks to StandardSetController capabilities.

There is also very good article on Salesforce blog on various approaches suggested for pagination and one of them is using StandardSetController.

To keep article simple, I am posting complete Visualforce and Apex code with Comments inside. Account object is used as an example here.

Create Simple Mass Delete Button for ListView using Salesforce Ajax Toolkit

In Many situation, I needed a Mass Delete Kind of button. Where, i can select records in ListView and simply click “Delete” button.

In this example, we will create a simple List View button and add on “Search Layout” of that object.

Salesforce Mass Delete Button - List View
Salesforce Mass Delete Button – List View

So, create a new Custom Button with following property:

  1. Display Type :  List Button
  2. Behavior : Execute JavaScript
  3. Content Source :  OnClick JavaScript

and use below Source code: