Listview in Apex in salesforce and with test class:
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.
Apex class :
1
/**
2
* Description : Controller Class to show How to utilize existing List View in Apex with Pagination Support
3
*
4
* Author : Jitendra Zaa
5
*/
6
publicwith sharing classListViewDemo {
7
8
privateString baseQuery = 'Select ID, Name FROM Account ORDER BY NAME ASC';
No comments:
Post a Comment