Fieldset in Salesforce | Techila
single,single-post,postid-2257,single-format-standard,ajax_updown_fade,page_not_loaded,,qode_grid_1300,footer_responsive_adv,hide_top_bar_on_mobile_header,qode-content-sidebar-responsive,qode-theme-ver-9.4.2,bridge,wpb-js-composer js-comp-ver-4.12,vc_responsive

Fieldset in Salesforce


Fieldset in Salesforce

A field set is a grouping of fields. For example, you could have a field set that contains fields describing a user’s first name, middle name, last name, and business title. 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.

 Field sets are available for Visualforce pages on API version 21.0 or above. You can have up to 50 field sets referenced on a single page.

Working with Field Sets Using Visualforce

Field sets can be directly referenced in Visualforce by combining the $ObjectType global variable with the keyword FieldSets. For example, if your Contact object has a field set called properNames that displays three fields, your Visualforce page can reference the field data through the following iteration:

<apex:page standardController=”Contact”>

   <apex:repeat value=”{!$ObjectType.Contact.FieldSets.properNames}” var=”f”>

       <apex:outputText value=”{!Contact[f]}” /><br/>



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:

  1. Type: The data type for the field.
  2. Label: The UI label for the field.
  3. FieldPath: Lists the field’s spanning info.
  4. Required: Indicates whether the field is required in the field set.
  5. DBRequired: Indicates whether the field is required for the object.

For example, you can access the labels and data types for the fields in properNames like this:

<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 value=”{!f.Label}”>

               <apex:facet name=”header”>Label</apex:facet>


           <apex:column value=”{!f.Type}” >

              <apex:facet name=”header”>Data Type</apex:facet>





If this Visualforce page is added to a managed package and distributed, subscribers can edit the properNames field set. The logic for generating the Visualforce page remains the same, while the presentation differs based on each subscriber’s implementation. To reference a field set from a managed package, you must prepend the field set with the organization’s namespace.

Field Set Considerations

Fields added to a field set can be in one of two categories:

  • If a field is marked as Available for the Field Set, it exists in the field set, but the developer hasn’t presented it on the packaged 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.
  • If a field is marked as In the Field Set, the developer has rendered the field on the packaged Visualforce page by default. Administrators can remove the field from the page after the field set is deployed by removing it from the In the Field Set column.

The order in which a developer lists displayed fields determines their order of appearance on a Visualforce page.

As a package developer, keep the following best practices in mind:

  • Subscribers with installed field sets can add fields that your page didn’t account for. There is no way to conditionally omit some fields from a field set iteration, so make sure that any field rendered through your field set works for all field types.
  • We recommend that you add only non-essential fields to your field set. This ensures that even if a subscriber removes all fields in the field set, Visualforce pages that use that field set still function.

Courtesy :

“Know more about Salesforce Consulting at Techila”

Author: techila

No Comments

Post A Comment