FieldSet with Visualforce Page

You can use dynamic bindings to display field sets on your Visualforce pages. A field set is a grouping of fields.

Scenario is, suppose we want to display field on visualforce page through standard controller.
Simply we have to write code for that like 
<apex:inputfield value="{!Account.Name}"/>
but here we have to made a functionality - user can add and remove or reorder field anytime. it automatically add in visualforce Page. This can be achieve by "Dynamic Visualforce Binding and field set"
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.


FieldSet Name - Accountfield

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

<apex:page standardController="Account">
    <Apex:form >
     <apex:pageBlock >
        <Apex:pageBlockSection title="Account" collapsible="false">
                <Apex:inputField value="{!Account.Name}"/>
                <apex:repeat value="{!$ObjectType.Account.FieldSets.AccountField}" var="f">
                        <apex:inputfield value="{!Account[f]}" /><br/>
                </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:



Note:  You can have up to 50 field sets referenced on a single page.

0 comments:

Post a Comment