Display fieldset in visualforce page

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

For example, you could have a field set that contains fields describing a Candidate Number, First name, Last name,Email. If the page is added to a managed package, administrators can add, remove, or reorder fields in a field set to modify the fields presented on the Visualforce page without modifying any code.

To display field set in visualforce page :

Field sets can be directly referenced in visualforce by combining the $ObjectType global variable with the keyword FieldSets. Bellow code will refer field set named 'Employee_Details' on BlogManage__Candidate__c  object.

{!$ObjectType.BlogManage__Candidate__c.FieldSets.Employee_Details}

  1. $ObjectType -> Global variable.
  2. BlogManage__Candidate__c -> Object API name.
  3. FieldSets -> Keyword to refer field set in VF page.
  4. Employee_Details -> Field set API name.

You can also choose to render additional information, such as field labels and data types, through the following special properties on the fields in the field set:

Property Name      Description

dbrequired              Indicates whether the field is required for the object
FieldPath               Lists the field’s spanning info
Label                     The UI label for the field
Required                Indicates whether the field is required in the field set
Type                     The data type for the field

For example :

You can use field set as a output(To view field set field values) and input(To get input for field set values) in visualforce page as bellow,


<!-- To display/view field set field values using field set-->

<apex:pageBlockSection title="Information Display" columns="2">
	<apex:repeat value="{!$ObjectType.BlogManage__Candidate__c.FieldSets.Employee_Details}" var="employeeVar">
        <apex:outputField value="{!BlogManage__Candidate__c[employeeVar.fieldpath]}"  />
    </apex:repeat>
</apex:pageBlockSection>
            
<!-- To get input using field set-->

<apex:pageBlockSection title="Information Input" columns="2">
    <apex:repeat value="{!$ObjectType.BlogManage__Candidate__c.FieldSets.Employee_Details}" var="employeeVar">
        <apex:inputField value="{!BlogManage__Candidate__c[employeeVar.fieldpath]}" required="{!OR(employeeVar.required, employeeVar.dbrequired)}" />
    </apex:repeat>
</apex:pageBlockSection>
            

Happy Coding :)

Rating: 
Average: 5 (1 vote)