2

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:form>
       <apex:selectList value="{!filterid}" size="1">
           <apex:selectOptions value="{!listviewoptions}"/>
       </apex:selectList>
       <apex:commandButton value="Go" action="{!list}"/>
   </apex:form>
</apex:page> 

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.

2
  • Hi Pramod, great question, might I suggest you consider renaming your question to something like 'Help understanding code behind a Visualforce page?'. This will make it more valuable for others in the future and also attact more people to your question, upvotes etc.. Just a thought... :) Commented Nov 24, 2012 at 15:23
  • 2
    Edited question title
    – metadaddy
    Commented Nov 24, 2012 at 21:45

2 Answers 2

7

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 Force.com 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. Force.com 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.

3
  • Thanks a lot @Andrew for explaing the answer so beautifully :) Commented Nov 24, 2012 at 17:03
  • Your very welcome, glad you appreciated it. Commented Nov 24, 2012 at 17:36
  • @AndrewFawcett Thank you so much for explaining, could you please suggest if is there any way to assign the default listView instead of showing all the list views?
    – gs650x
    Commented May 18, 2019 at 14:59
4

http://www.salesforce.com/us/developer/docs/pages/Content/pages_controller_sosc_list_views.htm

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 .

1
  • Thanks @PramodKumar.Please post questions on stackexchange if you are in difficulty and its always good to discuss and find optimized solution . Commented Nov 24, 2012 at 18:24

You must log in to answer this question.

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