Showing posts with label Field Set. Show all posts
Showing posts with label Field Set. Show all posts

Friday, June 1, 2012

Field Set in Salesforce


Field Set in Salesforce:
     Field set is a grouping of fields. You can use Dynamic bindings to display field sets in VF page. For example we have created Field Set on Contact object and add Account Name, First Name, Last etc. Then we can use in VF page.

*Note: Field Set is available for VF pages on API version 21.0 or above.
How to create Field Set?
Go to Set Up>Select Object>Click on Field Set
Enter:  Field Set Label>--------- (Write Field set label)
           Field Set Name>--------- (same as Label)
           Where is this used? ------ (Description)
   Click on Save>
  Click on Edit> Page Layout open

1. Available for the Field Set: A list of fields available for this Field Set. The fields can be moved into the Field Set and rendered on a Visualforce page. Administrators can display the field after the field set is deployed by moving it from the Available column to the In the Field Set column.
2. In the Field Set: A list of fields that are in the Field Set and rendered on the Visualforce page. This is contains field names e.g Account Name, First Name, etc. upto 50 fields.

Drag and drop fields in ‘In the Field Set’.         
Click on Save.

Apex Page:
<apex:page standardController="Contact">
<apex:pageBlock title="Fields in Proper Names">
<apex:pageBlockTable value="{!$ObjectType.Contact.FieldSets.properNames}" var="f">

<apex:column value="{!f}">
<apex:facet name="header">Name</apex:facet>
</apex:column>

<apex:column value="{!f.Label}">
<apex:facet name="header">Label</apex:facet>
</apex:column>

<apex:column value="{!f.Type}" >
<apex:facet name="header">Data Type</apex:facet>
</apex:column>

 <apex:column value="{!f.DBRequired}">
<apex:facet name="header">DBRequired</apex:facet>
</apex:column>

<apex:column value="{!f.FieldPath}">
<apex:facet name="header">FieldPath</apex:facet>
</apex:column>

</apex:pageBlockTable>
</apex:pageBlock>
</apex:page>

Friday, March 9, 2012

Using Field Set on Visual Force Page

This is about how we can use Field Set. We can dynamically bind fields on our visual force page using Field Set. It is very useful when we are working with managed package.

A field set is a grouping of fields. For example we can have a field set that contains fields "Name , Email , Phone , Mobile". If the page is added to a managed package, administrator can add, remove, or reorder fields in a field set to modify the fields presented on visual force page without modifying any code. Creating a field set : Go to Setup > App Setup > Create > Objects > Select your object > Field Set (Beta) > New : 



Fields in "In the Field Set" section is displayed on visual force page and administrator can add more fields in "In the Field Set" from "Available for the Field Set" section.

Visual Force Page Code :

<apex:page id="pageId" standardcontroller="My_Object__c">  
<apex:form id="formId">  
    <apex:pageblock id="pbId">  
        <apex:pageblocksection columns="1" id="pbsIs">  
            <apex:repeat value="{!$ObjectType.My_Object__c.FieldSets.MyFieldSet}" var="f">  
                <apex:inputfield value="{!My_Object__c[f]}">  
            </apex:inputfield></apex:repeat>  
        </apex:pageblocksection>  
    </apex:pageblock>  
</apex:form>  
</apex:page>  
Now it will show three fields (Name, Email, Mobile) on visual force page, if we add "Phone" field from "Available for the Field Set" section to "In the Field Set" section then four fields (Name, Email, Mobile, Phone) will be displayed on visual force without changing the code.