I am creating a very simple VR page based on standard list controller - I am very new to VF :-) Mostly my page is working well but I want to populate the headerValue for each column based on a field in the object. When I try this (code below) the value is just set to the literal name of the field - so the column header is set to Display_Label1__c. All my other expressions are working correctly with the list data.

<apex:pageBlockTable value="{!inv}" var="i" id="theList">
 <apex:column headerValue="{!i.Display_Label1__c}" value="{!i.Display_Value1__c}" style="background:{!i.Display_Color__c}"/>

1 Answer 1


The following will get you close to what you are after:

 <apex:pageBlockTable value="{! contacts }" var="c">
     <apex:variable value="{!c.FirstName}" var="colName"/>
     <apex:column value="{! c.FirstName }" headerValue="{!colName}"/>         

The name of the column will change based on the records being displayed.

The problem with the solution is that it only makes sense if all the records in the list have the same value in the column being displayed (in which case there is not much point displaying the column to the user as its not conveying any useful information).

For example if I have a list of records with first names of

Peter Peter Peter

Then the column will be called Peter and we do the dance of joy.

However if the list of names is:

Peter Paul Mary

Then the column will be called Mary as that is the last record rendered by the pageBlockTable.

Worse if your list is long and goes across multiple pages then the heading will change to the last record rendered on each page. So if I have

Page 1

Peter Paul

Page 2


Then the heading in Page 1 would be Paul but once I go to Page 2 it would be Mary.

  • Thanks Peter and Vamsi. This did work for the column header however still not quite clear why an expression referencing a variable would be evaluated when a field in the object is not.
    – debraSF
    Commented Feb 26, 2015 at 4:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .