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
Mathew Andresen 5Mathew Andresen 5 

apex repeat through list of contacts connected to an opportunity

Hi,

I'm trying to use apex:repeat to loop through the list of contacts attached to a opportunity (through the account), but I'm getting an error.  I assume my dot notation is messed up.

What I have is
 
<apex:repeat value="{!Opportunity.account.contacts}" var="con">

Thanks,
Prateek Singh SengarPrateek Singh Sengar
Hi Mathew,
Can you please share the error that you are receiving. Also can you please specify if you are using standard controller or extension. if its an extension can you please share the code as well.
Amit Chaudhary 8Amit Chaudhary 8
Similer code for account
<apex:page standardController="Account" recordSetVar="accounts" tabstyle="account" sidebar="false">
    <apex:pageBlock >
          <apex:repeat value="{!accounts}" var="a">
<apex:pageBlockSection title="{!a.name}"></apex:pageBlockSection>
  <apex:relatedList list="Contacts" subject="{!a.Id}"/>
<apex:relatedList list="Opportunities" subject="{!a.Id}" />
</apex:repeat>      
     </apex:pageBlock>
</apex:page>
You can change according to your requirement
 
Gunnam RamGunnam Ram
I have the same problem earlier and tried to get the reference with no success. Then I did below. Hope it will work for you.

Your Page:
<apex:page standardController="Opportunity">
   <apex:outputText value="{!Opportunity.Account}" rendered="false" />
   <apex:iframe src="/apex/DesiredPage?id={!Opportunity.AccountId}" />
</apex:page>

Desired Page:
<apex:page standardController="Account" showheader="false" sidebar="false">
   <apex:dataTable value="{!Account.Contacts}" var="con">
       <apex:column headerValue="Name" value="{!con.Name}"/>
   </apex:dataTable>
</apex:page>


 
Mathew Andresen 5Mathew Andresen 5
I'm using standard controller for opportunity.

Error is   "Error: Aggregate Relationship is used in an unsupported complex expression containing 'Account.contacts'"

more complete code is 
<apex:page standardController="Opportunity"  showHeader="false" renderAs="pdf">
    
  
    <apex:form >
        
            <b> <center><font size="4">{!Opportunity.Account.Name} - {!opportunity.spec_sheet__r.Brand__c} Spec Sheet </font></center></b>
        
        <br/>
        <hr/>
        <p><b><font color="#000080"  face="Arial">Client Information</font></b></p>   
        <table border="0" cellspacing="0" cellpadding="0" width="100%">
            <tr>
                <td width = "50%">Contract No: {!Opportunity.Contract_Number__c} </td>
                <td >Contract Date: <apex:OutputField value="{!Opportunity.CloseDate}"/> </td>                  
                
             </tr>
            <tr>

                <td>Bond Number: {!Opportunity.account.Bond_Number__c} </td>
              
            </tr>
            <tr>
            <apex:repeat value="{!Opportunity.account.contacts}" var="con"> 
                <td>Contact Name: {!Opportunity.account.Billing_Contact_Name__c}</td>
                <td>Contact Phone Number:  {!Opportunity.account.Billing_Phone__c}</td>
                <td>Contact Email: {!Opportunity.account.Billing_Email__c}</td>    
               </apex:repeat>          
            </tr>
            
        </table>
 
        <hr/>
<!-- *********************************************************************************************************8  --> 
        <p><b><font color="#000080"  face="Arial">Bottling info</font></b></p>        
           <apex:repeat value="{!Opportunity.OpportunityLineItems}" var="line">
          <apex:outputtext rendered="{!if(line.PricebookEntry.Name=='Finished Goods',true,false)}" >
          <table border="0" cellspacing="0" cellpadding="0" width="100%" >
              <tr><th>Variety</th>
              <th>Vintage</th>
              <th>Appellation</th>
              <th>Alc %</th>
              <th>CaseQuantity</th></tr>
             <tr>
             <td>{!line.Variety__c}</td>
             <td>{!line.Vintage__c}</td>              
             <td>{!line.Appellation__c}</td> 
             <td>{!line.Alc_Percent__c}</td>               
             <td>{!line.Quantity}</td>
             </tr>
                      </table>
             </apex:outputtext>
    </apex:repeat>   
        
           <apex:repeat value="{!Opportunity.OpportunityLineItems}" var="line">
          <apex:outputtext rendered="{!if(line.PricebookEntry.Name=='Finish & Bottle Services',true,false)}" >
          <table border="0" cellspacing="0" cellpadding="0" width="100%" >
              <tr>
              <th bgcolor="#C0C0C0">Variety</th>
              <th bgcolor="#C0C0C0">Vintage</th>
              <th bgcolor="#C0C0C0">Appellation</th>
              <th bgcolor="#C0C0C0">Alc %</th>
              <th bgcolor="#C0C0C0">Case Quantity</th></tr>
             <tr>
             <td>{!line.Variety__c}</td>
             <td>{!line.Vintage__c}</td>              
             <td>{!line.Appellation__c}</td> 
             <td>{!line.Alc_Percent__c}</td>               
             <td>{!line.Quantity}</td>
             </tr>
                      </table>
             </apex:outputtext>
    </apex:repeat>         
        <hr/>

 <!-- *********************************************************************************************************8  -->   
        <p><b><font color="#000080"  face="Arial">Packaging</font></b></p> 
        <table border="0" cellspacing="0" cellpadding="0" width="100%" id="table2">
        <tr><th>Item</th><th>Vendor</th></tr>
            <tr>
                <td>Glass: {!if(Opportunity.spec_sheet__r.glass__c = "Client Provided",opportunity.spec_sheet__r.Glass_Text__c,Opportunity.spec_sheet__r.glass__c)}</td>
                <td>{!if(Opportunity.spec_sheet__r.glass__c = "Client Provided","Client",Opportunity.spec_sheet__r.glass_vendor__c)}  </td>
            </tr>
            
            <tr>
                <td>Carton: {!if(Opportunity.spec_sheet__r.carton__c = "Client Provided",opportunity.spec_sheet__r.carton_Text__c,Opportunity.spec_sheet__r.carton__c)}</td>
                <td>{!if(Opportunity.spec_sheet__r.carton__c = "Client Provided","Client",Opportunity.spec_sheet__r.carton_vendor__c)}  </td>
            </tr>            

            <tr>
                <td>Closure: {!if(Opportunity.spec_sheet__r.closure__c = "Client Provided", Opportunity.spec_sheet__r.Closure_Text__c, Opportunity.spec_sheet__r.closure__c) } </td>
                <td> {!if(Opportunity.spec_sheet__r.closure__c = "Client Provided", "Client", Opportunity.spec_sheet__r.closure_vendor__c) }  </td>
            </tr>

            <tr>
                <td>Capsule: {!if(Opportunity.spec_sheet__r.capsule__c="Client Provided",Opportunity.spec_sheet__r.Capsule_Text__c, Opportunity.spec_sheet__r.capsule__c)  }</td>  
                <td> {!if(Opportunity.spec_sheet__r.capsule__c="Client Provided","Client", Opportunity.spec_sheet__r.capsule_vendor__c)  }  </td>

            </tr>
          
            <tr>
                <td>Carton Label: {!opportunity.spec_sheet__r.Carton_Label__c}</td>
            </tr>
            
        </table>            
    <hr/>
  
        
<!-- *********************************************************************************************************8  -->        
        <p><b><font color="#000080"  face="Arial">Wine Making - {!Opportunity.account.wine_maker__r.name}</font></b></p>

<table border="0" width="90%">
    <tr><td width="30%">Completed Under Bond Number: {!if(opportunity.Completed_Under_Bond__c = "Client Bond Number", Opportunity.account.bond_number__C, opportunity.Completed_Under_Bond__c)}</td></tr>
       <tr><td>Wine Bulked in? {!opportunity.bulk_in__c}</td></tr>
       <tr>
   
            <apex:outputtext rendered="{!if(opportunity.Crossflow__c,true,false)}" > <td>Crossflow: <img src="/img/checkbox_checked.gif"/> </td> </apex:outputtext>
            <apex:outputtext rendered="{!if(opportunity.Crossflow__c,false,true)}"> <td>Crossflow: <img src="/img/checkbox_unchecked.gif"/>  </td> </apex:outputtext>

                 
            <apex:outputtext rendered="{!if(opportunity.Alc_Removal__c,true,false)}"> <td>Alc Removal: <img src="/img/checkbox_checked.gif"/> </td> </apex:outputtext>
            <apex:outputtext rendered="{!if(opportunity.Alc_Removal__c,false,true)}"> <td>Alc Removal: <img src="/img/checkbox_unchecked.gif"/> </td> </apex:outputtext>

            <apex:outputtext rendered="{!if(opportunity.VA_Removal__c,true,false)}"> <td>VA Removal: <img src="/img/checkbox_checked.gif"/> </td> </apex:outputtext>
            <apex:outputtext rendered="{!if(opportunity.VA_Removal__c,false,true)}"> <td>VA Removal: <img src="/img/checkbox_unchecked.gif"/> </td> </apex:outputtext>        
                   
        </tr>
        <tr>
            
            <apex:outputtext rendered="{!if(opportunity.Cold_Stability__c,true,false)}"> <td>Cold Stablity: <img src="/img/checkbox_checked.gif"/> </td> </apex:outputtext>
            <apex:outputtext rendered="{!if(opportunity.Cold_Stability__c,false,true)}"> <td>Cold Stablity: <img src="/img/checkbox_unchecked.gif"/> </td> </apex:outputtext>             
              
           <td>Beginning Alc: <apex:outputField value="{!opportunity.Beginning_Alc__c}"/> </td> 
            
            <apex:outputtext rendered="{!if(opportunity.no_treatment__c,true,false)}"> <td>None: <img src="/img/checkbox_checked.gif"/> </td> </apex:outputtext>
            <apex:outputtext rendered="{!if(opportunity.no_treatment__c,false,true)}"> <td>None: <img src="/img/checkbox_unchecked.gif"/> </td> </apex:outputtext>           
   
        </tr>  
        <tr>
            <apex:outputtext rendered="{!if(opportunity.Heat_Stability__c,true,false)}"> <td>Heat Stability: <img src="/img/checkbox_checked.gif"/> </td> </apex:outputtext>
            <apex:outputtext rendered="{!if(opportunity.Heat_Stability__c,false,true)}"> <td>Heat Stability: <img src="/img/checkbox_unchecked.gif"/> </td> </apex:outputtext> 
   
           <td>Finished Alc: <apex:outputField value="{!opportunity.Finished_Alc__c}"/> </td>  
           <td>Other: <apex:outputField value="{!opportunity.other_treatment__c}"/> </td> 
        </tr>
    </table>

        <br/>

          <table border="0" cellspacing="0" cellpadding="0" width="100%" >
              <tr>
              <th bgcolor="#C0C0C0">Lot #</th>              
              <th bgcolor="#C0C0C0">Variety</th>
              <th bgcolor="#C0C0C0">Vintage</th>
              <th bgcolor="#C0C0C0">Appellation</th>
              <th bgcolor="#C0C0C0">Alc %</th>
              <th bgcolor="#C0C0C0">Gallons</th></tr>
           <apex:repeat value="{!Opportunity.OpportunityLineItems}" var="line">
          <apex:outputtext rendered="{!if(line.PricebookEntry.Name=='Bulk Wine',true,false)}" >              
             <tr>
             <td>{!line.Item_Id__c}</td>              
             <td>{!line.Variety__c}</td>
             <td>{!line.Vintage__c}</td>              
             <td>{!line.Appellation__c}</td> 
             <td>{!line.Alc_Percent__c}</td>               
             <td>{!line.Quantity}</td>
             </tr>

             </apex:outputtext>    
        </apex:repeat>
                       </table>       
        
        
        <hr/>
<!-- *********************************************************************************************************8  -->          
  <p><b><font color="#000080"  face="Arial">Special Notes</font></b></p>
  {!opportunity.special_notes__c}

    
    </apex:form>
    
    
</apex:page>

 
swati_sehrawatswati_sehrawat
Try this link https://developer.salesforce.com/forums/?id=906F0000000973BIAQ and see if it can help you.
swati_sehrawatswati_sehrawat
It has the same issue which you are facing.