Wednesday, March 26, 2014

Understanding recordSetVar tag in Visualforce Page

This attribute indicates that VF page uses set oriented standard controller. The value of the attribute indicates name of the set of records passed to the page means collection records. This record set can be used in the expressions to return values for display on the page or to perform actions on set of records. See this example:
   
Page:

<apex:page standardController="Account" recordSetVar="accounts" extensions="recordSetVarController">
<apex:form >
<apex:pageBlock >
    
    <apex:pageBlockTable value="{!accounts}" var="a" >
        <apex:column value="{!a.Id}"/>
        <apex:column value="{!a.name}"/>
    </apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>


Controller
public class recordSetVarController {
    public List<Account> obj{get;set;}
    public string str{get;set;}
    public recordSetVarController(ApexPages.StandardSetController controller) {
        obj = (List<Account>) controller.getSelected();
    }
}
 Or for example given below VF page, if your page is using the standard accounts controller, and recordSetVar is set to "accounts", you could create a simple pageBlockTable of account records by doing the following:

<apex:pageBlockTable   value="{!accounts}" var="a">
<apex:column value="{!a.name}"/>
</apex:pageBlockTable>

VF Page:
<apex:page standardController="Account" recordSetVar="accounts">
 <apex:dataList var="a" value="{!accounts}" type="1">
     {!a.name}
    </apex:dataList>
    </apex:page>
            Above displays all account with number.

*Note: For this page we can override List, Accounts Tab, and Custom List buttonsonly and not the New/View/Edit/Delete buttons. Because these buttons are working for single record not for multiple record action.