Find your content:

Search form

You are here

Help understanding code behind a Visualforce page


I am newbie to salesforce so i am getting little problem to understand the code. so anyone of you may please explain the below code :-

<apex:page standardController="Account" recordSetVar="accounts">
       <apex:selectList value="{!filterid}" size="1">
           <apex:selectOptions value="{!listviewoptions}"/>
       <apex:commandButton value="Go" action="{!list}"/>

I am not getting what is this "filterid" thing and where can i find this. If is a field in Account object then i didn't find this in account Object.

Attribution to: Pramod Kumar

Possible Suggestion/Solution #1

I guess you are referring to this document.

1)FilterId is not any field on account .Each of the List views that you create inside the salesforce for standard Account Object gets a filterid assigned automatically.

2)listviewOptions store all the list views you have created for Account Object and it displays these list views for the user to select

3)When you click go button the listviewOption selected by the User and according to the filterid assigned the whole list view is rendered .

Attribution to: Mohith Shrivastava

Possible Suggestion/Solution #2

Visualforce uses the MVC pattern, pages have code behind them as well as data. You make 'bindings' in your page e.g. {!filterId} or {!list} to access data or methods (behaviour) on the code behind the page. The code behind a page is known as the controller.

In your example you have specified the 'standardController' attribute. This tells the platform that you want to utilise the default standard controller as apposed to one you write in Apex. There are two types of standard controllers, one for detail (single record) and one for list (multiple records) views.

As you have specified the 'recordSetVar' attribute. will utilise the StandardSetController behind your page. Thus the methods and data on that controller are available to bind to. You can view the documentation and definition of the 'filterId' and 'listviewoptions' methods in the standard documentation here. Note that when binding to methods starting with 'get' or 'set' you drop this when binding to them.

enter image description here

This topic Using List Views with Standard Set Controllers gives a good overview of Visualforce pages using list views and is well worth checking out. This topic in the Visualforce developers guide will help you understand Visualforce more generally and also more about writing your own Apex controllers that either replaces the standard controllers or extending them. Good luck and enjoy!

Update:. I could not find reference to the 'list' method used in your commandButton action binding above, suspect this is an oversight. As you probably have discovered its behaviour is to redirect to the list view page of the object. It appears to pass the current value of the 'filterid' property to the page.

Attribution to: Andrew Fawcett
This content is remixed from stackoverflow or stackexchange. Please visit

My Block Status

My Block Content