Salesforce Learning Guide

Tuesday 18 November 2014

What is a fieldset?

In this section i will explain about what is a fieldset? How can we create that? and how can we use that in a visualforce page?

Fieldset is a grouping of fields, you can use this fieldset in visualforce page to display that group of fields in that page. If you are using field set in visualforce to display fields, then you can add, remove & reorder fields very easily. No need to do code modifications to the page, In fieldset only you can add, remove & reorder fields. Generally these field sets are useful in managed packages. In manged packages , If you used field set in visualforce pages, administrators can easily add, remove and reorder fields in page. As an administrator, you can create or edit field sets and also you can edit installed fieldsets.

How to create a fieldset?
To create a fieldset, go to object, you want create fieldset by clicking on new button. Enter required fields and save. We will get below screen to add fields to field set.
Fieldset In Salesforce
Using fieldsets is very easy & you can drag and drop to arrange fields in fieldsets.

How to use field set in a visualforce page?
Below code is simple visualforce, it explains about how to use fieldset in a visualforce page.
<apex:page id=”pageId” standardcontroller=”Registration__c”>
<apex:form id=”formId”>
<apex:pageblock id=”pb”>
<apex:pageBlockSection >
<apex:repeat value=”{!$ObjectType.Registration__c.FieldSets.Registration_req_fields}” var=”fs”>
<apex:inputfield value=”{!Registration__c[fs]}”>
</apex:inputfield></apex:repeat>
</apex:pageBlockSection>
<apex:pageBlockButtons >
<apex:commandButton value=”Submit Details” action=”{!Save}”/>
</apex:pageBlockButtons>
</apex:pageblock>
</apex:form>
</apex:page>
The above code displays all fields in the field set. See the below screen to see the output of above code.
Fieldset
No need to change the code to re arrange fields in this page. What ever the order you created/edited in field set, the same order will display on this page.
We can easily make fields required. It is drag drop tool like page layout. To make required, double click on the field and check the required check box.

Important point about field sets:
- In the field set, you can span to fields that reference multiple objects. When you span a field into a field set that references multiple objects, the only field you can span to is the Name object.
- The total number of cross object spans within the In the Field Set container can’t exceed 25.

0 comments:

Post a Comment

Note: only a member of this blog may post a comment.