Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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

2 Answers 2

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}"/>
  </apex:repeat>
</apex:pageBlockTable>

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}"/>
  </apex:repeat>
</apex:pageBlockTable>

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 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 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 at 15:36

Your Answer

 
discard

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.