Skip to main content
So I'm trying to post a field history on a visual force page from a custom object but dont know how to display it on the visualforce page.

 

Here is my code:

 

In my Controller - 

 

List<Customer_Health__c> History {get;set;}

History = [SELECT Name, (SEELCT NewValue FROM Histories) FROM Customer_Health__c WHERE Id= :CHIdNum];

Public List<Customer_Health__c> getHistory(){return History;}

Page

<apex:repeat value="{!History}" var="hh">

<tr>

<td><apex:outputText value="{!hh.Histories.NewValue}"></apex:outputText></td>

</tr>

</apex:repeat>

 

I get an Error for Unknown Property 'VisualforceArrayList.NewValue'

 

2 answers
  1. Jul 24, 2014, 2:45 AM
    I do not know off the top of my head if "Histories" is the right child relationship, but assuming it is. 

     

    You have a list of History items even though you only actually select one record based on setting the id. Your controller would be better like this: 

     

    public Customer_Health__c customerHealth {get; set;}

     

    List<Customer_Health__c> customerHealths = new List<Customer_Health__c>([SELECT Name, (SEELCT NewValue FROM Histories) FROM Customer_Health__c WHERE Id= :CHIdNum]);

     

    if (!customerHealths.isEmpty) customerHealth = customerHealths.get(0);

     

    You also do not need that get method, that is what you are doing already with the {get;set;} stubs

     

    I still use lists as query results to catch errors when the query returns no records

     

    Then because what actually want to repeat if the Histories child records from the main Customer_Health__c record, your page can look like:

     

    <apex:repeat value="{!customerHealth.Histories}" var="hh">

     

        <tr>

     

              <td><apex:outputText value="{!hh.NewValue}" /></td>

     

        </tr>

     

    </apex:repeat>

     

    You can also look at apex:dataTable tag which will do the table rows and cells for you, or apex:pageBlockTable which will use the default salesforce styles. That is more personal preference though, not required to make it work. 
0/9000