1

I am using Field Set in Visualforce pages to render user-defined fields.

<apex:pageBlockSection title="HARDCODED TITLE">
    <apex:repeat value="{!$ObjectType.Account.fieldsets.SystemFields}"
       ....
    </apex:repeat>
</apex:pageBlockSection>

Instead of giving the enclosing section a hard-coded title I would like to dynamically reference / display the Field Sets Label like this:

<apex:pageBlockSection title="{!$ObjectType.Account.fieldsets.SystemFields.Label}">
    <apex:repeat value="{!$ObjectType.Account.fieldsets.SystemFields}"
       ....
    </apex:repeat>
</apex:pageBlockSection>

This is not possible as the variable exposes a FieldSetMember Array. Is there any workaround (without additional Controller code) or an Idea to vote for?

2 Answers 2

2

Late answer but I just worked on my solution for this and wanted to share. There is not solution without controller code that I can find but here's one with minimal additions.

Getting a single fieldset name

To get the name of a single fieldset you can create a variable in the controller:

public String fieldSetName { get; set; }

then in the constructor you could use:

fieldSetName = Schema.SObjectType.Case.fieldSets.getMap().get('fieldSetApiName').getLabel();

and finally in the VF page:

<apex:pageBlockSection title="{!fieldSetName}">

Multiple fieldsets

If you are working with multiple field sets my solution has been to create a map of titles.

public Map<String,String> fieldSetNames { get; set; }

Then use a function you can call from the constructor.

public void loadFieldsSetMap(){
    Map<String, Schema.FieldSet> fsMap = Schema.SObjectType.Account.fieldSets.getMap();
    fieldSetNames = new Map<String, String>();
    for(String i : fsMap.keySet() ){
        fieldSetNames.put(i, fsMap.get(i).getLabel());      
    }
}

In the page I then call the relevant map entry with the name in lowercase

<apex:pageBlockSection title="{!fieldSetNames['fieldsetapiname']}">
<apex:repeat value="{!$ObjectType.Account.fieldsets.fieldSetApiName}"
   ....
</apex:repeat>

Hope this helps.

-1

Instead of hard coded value I would use custom label.

1
  • 1
    your answer is appreciated, however in order to be of value to the person looking for the answer you should qualify it with a why and how.
    – Bartley
    Jan 22, 2015 at 17:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.