function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
AkiTAkiT 

How to build table of records and childs

I have "Tender" object as a child for opportunity. Tender again has versions as a child.

I wanted to create VF section in opp detail page that shows a table of all Tenders and Tenders' versions.

I build a opportunity controller extension that queries the Versions. The query is:

Code:
...

public List<FL_Tender__c> getTenders() {
  if(tenders == null) tenders = [select name, (select name, active__c from Versions__r) from FL_Tender__c];
  return tenders;
 }

...

 This class at least saves ok. But when I try to create the table in my VF page with following code:
Code:
<apex:page standardController="Opportunity" showHeader="true" tabStyle="Opportunity" extensions="TenderSectionTableController" >

<apex:dataTable value="{!Tenders}" var="tender" id="theTable" rowClasses="odd,even" styleClass="tableClass">
  <apex:facet name="header">Tenders & Versions</apex:facet>
  <apex:column>
      <apex:facet name="header">FL Tender</apex:facet>
   <apex:outputText value="{!tender.Name}"/>
  </apex:column>
  <apex:column>
   <apex:facet name="header">Version</apex:facet>
   <apex:outputText value="{!tender.Versions__r.Name}"/>
  </apex:column>
 </apex:dataTable>

</apex:page>

I get save error:
Save error: The class 'java.util.ArrayList' does not have the property 'Name'.   

I am not sure how to utilize these fields in VF that I get in Parent - Child SOQL query in my apex controller. Any advice?

 


mtbclimbermtbclimber
Code:
<apex:outputText value="{!tender.Versions__r.Name}"/>

 Versions__r is a relatonship name and represents a child relationship and thus a collection of versions. You need to iterate over them just like you are doing with the tender object records. 
jwetzlerjwetzler
also instead of this:
Code:
<apex:column>
   <apex:facet name="header">FL Tender</apex:facet>
   <apex:outputText value="{!tender.Versions__r.Name}"/>
</apex:column>

 try this:
Code:
<apex:column headerValue="FL Teder" value="{!tender.Versions__r.Name}"/>

 

yibongyibong
I have a same problem but your recommend is not working.
same error code appears.

Error: The class 'java.util.ArrayList' does not have the property 'UnitPrice'.   

in my case,

this is controller
Code:
public class quoteControllerExtension {

    public quoteControllerExtension(ApexPages.StandardController controller) {
    }

    Pricebook2 stdpb = [Select Id from Pricebook2 where IsStandard=true];                                 
    
    Quote__c quote = [SELECT id, name FROM Quote__c
                      WHERE id = :ApexPages.currentPage().getParameters().get('id')];
    //step 1
    // Build the list of  products                        
    Product2       product;    
    List<Product2> products;
    
    public List<Product2> getProducts() {        
        if (products == null) {
            products = new List<Product2>();
            product = null;
            List<Product2> product2s = new List<Product2>();
            product2s = [select id, name, family, description, selected__c , 
                        (select UnitPrice from PricebookEntries where Pricebook2Id = :stdpb.id limit 1) 
                        from product2 ORDER BY family];    
            for (Product2 product : product2s) {
                products.add(product);
            }
        }        
        return products;
    }

 this is VF page
Code:
<apex:page standardController="Quote__c" extensions="quoteControllerExtension">
<apex:form >
<apex:pageBlock >


<apex:pageblockTable value="{!products}" var="pdt">
<apex:column >
<apex:inputField value="{!pdt.selected__c}"/>
</apex:column>
<apex:column >
<apex:facet name="header">Item</apex:facet>
<apex:outputField value="{!pdt.name}"/>
</apex:column>
<apex:column headerValue="Standard Price" Value="{!pdt.pricebookEntries.UnitPrice}"/>

<apex:column >
<apex:facet name="header">Description</apex:facet>
<apex:outputField value="{!pdt.description}"/>
</apex:column>
<apex:column >
<apex:facet name="header">Category</apex:facet>
<apex:outputField value="{!pdt.family}"/>
</apex:column>
</apex:pageblockTable>

</apex:pageBlock>
</apex:form>


</apex:page>

 the red colored paragraph is the problem case.

is there any solution?

thanks.