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
SFDC-cloudSFDC-cloud 

VF with Parent Child relationship -- Error: Unknown property 'VisualforceArrayList.Opportunity'

I am trying to display the data returned by the below query but not successfull, 

 

SELECT ID,Name, (SELECT Opportunity.amount FROM OpportunityContactRoles Order BY Opportunity.CloseDate DESC Limit 1 ) FROM Contact Where Lead_Source_Contact__c ='abc'

 

How can I display opportunity.amount using visualforce ?

 

<apex:pageBlockTable value="{!searchResults}" var="o" rendered="{!NOT(ISNULL(searchResults))}">                    <apex:column headerValue="Name">               

        <apex:outputLink value="/{!o.Id}">{!o.Name}</apex:outputLink>      

         </apex:column>                   

  <apex:column value="{!OpportunityContactRoles.Opportunity.amount}"/> I am getting error message  Error: Unknown property 'VisualforceArrayList.Opportunity'

 

 

</apex:pageBlockTable>

 

TIA!!!!

 

Best Answer chosen by Admin (Salesforce Developers) 
tom_patrostom_patros

Can you post more of your Apex code?

 

I think part of the issue is you are trying to use a list (OppContactRoles) as a single record. Given the relationships in your query, even a limited result quantity (1) will be treated as a list.

 

You might try creating a <apex:repeat> inside the column and looping over OpportunityContactRoles, then output Opportunity.amount

All Answers

tom_patrostom_patros

Can you post more of your Apex code?

 

I think part of the issue is you are trying to use a list (OppContactRoles) as a single record. Given the relationships in your query, even a limited result quantity (1) will be treated as a list.

 

You might try creating a <apex:repeat> inside the column and looping over OpportunityContactRoles, then output Opportunity.amount

This was selected as the best answer
SFDC-cloudSFDC-cloud

I felt the same and tired....  I also took help with Dynimaic VF binding and that did not work... may be i was doing something wrong.

 

Below is my code... Thanks for your help.

 

public PageReference search() {     

  if (searchResults== null) {         

  searchResults= new List<contact>(); // init the list if it is null     

  }

else {         

  searchResults.clear(); // clear out the current results if they exist     

  }

 // use some dynamic soql to find the related opportunities by name  AccountId = \''+a.Id+'\'  , SELECT ID,Name, (SELECT Opportunity.amount FROM OpportunityContactRoles Order BY Opportunity.CloseDate DESC Limit 1 ) FROM Contact Where Lead_Source_Contact__c ='abc'  ;

  searchResults= Database.query(qry);   

    return null; 

  }