Tell me more ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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.

share|improve this question
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... :) – Andrew Fawcett Nov 24 '12 at 15:23
Thanks andrew.i will do so in upcoming questions :) – Pramod Kumar Nov 24 '12 at 16:44
2  
Edited question title – metadaddy Nov 24 '12 at 21:45

2 Answers

up vote 7 down vote accepted

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.

share|improve this answer
Thanks a lot @Andrew for explaing the answer so beautifully :) – Pramod Kumar Nov 24 '12 at 17:03
Your very welcome, glad you appreciated it. – Andrew Fawcett Nov 24 '12 at 17:36

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 .

share|improve this answer
Thanks buddy. Great Explanation :) – Pramod Kumar Nov 24 '12 at 16:50
Thanks @PramodKumar.Please post questions on stackexchange if you are in difficulty and its always good to discuss and find optimized solution . – Mohith Kumar Nov 24 '12 at 18:24

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.