Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a way to render the column headers of a even if the passed list is empty? I have the field labels already in place as I am iterating over a Fieldset.

<apex:pageBlockTable value="{!rows}" var="row">

            <apex:repeat value="{!fields}" var="field">

                <apex:column headerValue="{!field.Label}">
share|improve this question

I believe the problem is that you are binding to the data, which, when rendered with no results, is not there to reference.

Normally, without a field set you would bind to something in metadata. For instance like this:

<!-- meta describe example
<apex:column ... headerValue="{!$ObjectType.MyObj__c.fields.Field__c.label}"/>
<!-- custom label example
<apex:column ... headerValue="{!$Label.CustomLabelName}"/>

The describe example will simply pick up the label property of the field that you set when you defined it. The custom label example does need to be defined by going to Create > Custom Labels in the setup menu.

Using a fieldset, however, you need something more dynamic. Initially I tried the following:

<apex:pageBlockTable value="{!Account.Contacts}" var="c">
  <apex:repeat value="{!$ObjectType.Contact.FieldSets.SetOfFields}" var="field">
    <apex:column value="{!c[field]}" headerValue="{!c[field].label}"/>

In this way, I got no header label with my empty list of contacts.

But if I changed the header value as follows:

<apex:pageBlockTable value="{!Account.Contacts}" var="c">
  <apex:repeat value="{!$ObjectType.Contact.FieldSets.SetOfFields}" var="field">
    <!--  THE headerValue BELOW IS THE DIFFERENCE ----v -->
    <apex:column value="{!c[field]}" headerValue="{!field.label}"/>

This notation is referencing the metadata directly, and in this instance, with an empty list, I see my header labels.

enter image description here

share|improve this answer
I already use the FieldSetMembers 'field' Label for the header values instead of the empty lists 'row'. So this doesn't work. – Robert Sösemann Jul 31 '14 at 13:06
What you describe in your question as the problem seems to be what I'm solving. Can you share a screen shot of the undesired behavior for clarification? – Peter Jul 31 '14 at 13:58

Instead of deleting my question I decided to "answer" it. It did not work for another reason. The fieldset was not found when the list is empty as the code which fetches the fieldset relies on having at least one SObject in the list.

share|improve this answer
So it is driven by the way the Apex code fetches the fieldset? If so, that would be valuable to see in your question and in your answer. – Peter Jul 31 '14 at 15:36

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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