Using listViews to create dynamic columns in PageBlock in visualForce page

This is 2nd post from the blogpost that explains how can a developer creates a visualforce page with the flexibility for the client or admin to change fields by themselves without involving a developer. In my previous post, i explained about using field sets to do the same. In this post, i will explain another way i.e. using list views from the object.

In this approach, we can create custom list views on the object and use that list view to get all the fields used in the list view and display them in the visualforce page

Here is what you need to do that:
1) Enable rest API urls in remote Site Settings. Since listView method is only available in rest API, we need to do a callout to get the listView details.


2) In the controller, we will do the callout. I have hard-coded 2 parameters for this example, but you can make them dynamic as per your requirement
     a) objectApiName - This will store the API name of the object which you                need to query
     b) listViewId - This is the Salesforce id of the list view. you can query                    it(shown in the code as commented), or you can find it from the list view            URL (it starts with 00B), image below:



3) In the controller, i am getting 2 things from the response
    a) Query parameter - that contains the whole query from list view. YES,                 salesforce creates a query for you automatically
    b) Columns to Display - in the response, we have columns parameters, that           contains api name of the fields used in the listView. This will be used to             show the columns from the query. You can also split the columns name             from 1st parameter(query)

4) That is it, rest of the things are pretty obvious. A vf page to display the query     results in page block table.
SOURCE CODE AVAILABLE AT : gitHub

Output :


1 comment:

  1. Jackpot City Hotel and Casino, Dublin, Ireland - Mapyro
    View detailed 밀양 출장안마 information and reviews of Jackpot City 충청북도 출장안마 Hotel and 충청남도 출장안마 Casino, Dublin, Ireland. Hotel. 여수 출장샵 Mapyro: Information on Hotel Rooms, Photos, 목포 출장샵 Floor

    ReplyDelete