1

How to get the field label name from field set. I have created a fields set for custom object and I am trying to get the fiedset to display on VF page and I am able to get the fieldset display on VF page but now my requirement is to get the field Label. How can I get the field label name on VF page please guide me hoe can I get this working.

3 Answers 3

6

If f is the reference to a field within the fieldset, then all you need is f.label.

Example straight from the docs:

<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:pageBlockTable>

Other things you can reference in Visualforce:

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
1

I generally use this pattern to get the label:

<apex:repeat value="{!$ObjectType.myCustomObject__c.FieldSets.myFieldSet}" var="f">
    Field label: {!$ObjectType.myCustomObject__c.Fields[f].label
</apex:repeat>
0

If you are using standard page then you can use

{!$ObjectType.opportunity.fields.Name.label}

You must log in to answer this question.