Saturday, September 20, 2014

Fieldset visualforce page salesforce

Fieldset visualforce page salesforce

A field set is a grouping of fields for same object. We can use dynamic bindings to display field sets on our Visualforce pages. Fieldset is very useful when we are working with managed package.

A fieldset is a grouping of fields. For example, fieldset can contain fields like first name, last name, mobile, phone of user object. Consider a scenario, suppose we want to display some fields in a page and we want to keep the flexibility to change which fields are displayed. In such a scenario we should use field sets to add or remove the fields as per requirement.Which ever fields are included in the field set will be displayed in page. For this we will need to create a field set on object we wish, then we can access it directly in visualforce page.

Another scenario is, suppose visualforce code is part of managed package. In that case we can add, remove, or reorder fields in a field set to modify the fields presented on the Visualforce page without modifying any code.


In the example below, we will display one fieldset for account object then we will display fieldset fields on visualforce page.

First we need to create a fieldset. Go to Setup > Customize > Accounts > Field Set
Click on new. Enter all mandatory fields. Also drag and drop all required fields in fieldset.


Create account field set


Now we will create visualforce code which will use fieldset.
Visualforce Code:


<apex:page standardController="Account">
  <apex:form >
      <apex:pageblock >   
          <apex:pageBlockSection title="Account detail">
             <apex:repeat value="{!$ObjectType.Account.fieldsets.accountFieldSet}" var="fieldValue">
                 <apex:Inputfield value="{!Account[fieldValue]}"/>
             </apex:repeat>
          </apex:pageBlockSection>
      </apex:pageblock>
    </apex:form>
</apex:page>

We can add, remove, or reorder fields in a fieldset to modify the fields presented on the Visualforce page without modifying visualforce page code.
We will get following output in visualforce page:

fieldset Visualforce page



0 comments:

Post a Comment

 
| ,