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
BobPBobP 

Visualforce Repeat View Account related records and the related records child records

I have an interesting problem that i cant seemed to figure out.
I am trying to create a visualforce page pdf with one or apex:repeat components.
I wuold like to create a pdf from the account object that displays related records to the account object and also child record information that is associated to the related record of the account.

I tried creating the following code but i am getting an error.

Error: Unknown property 'VisualforceArrayList.Bid_Deliverables__r'


the first Apex:Repeat gets the related records to the account, the second should return the related records to the related object to the account. I'm not sure if this can be done. Any help would be greatly appreciated. 



 
<apex:page standardcontroller="Account" renderas="pdf" standardstylesheets="false" showheader="false" applyhtmltag="false">
<form >
<html xmlns="http://www.w3.org/1999/xhtml">
    <body>
    </body>
    
 <table align="center" width="85%" style="font-family: Arial, Helvetica, sans-serif; border-collapse: collapse;  text-align:center;"
               cellpadding="2">
            
<apex:repeat var="sd" value="{!Account.Bids_Sent4__r}">
                   
<tr>
<td style="border-bottom:solid;border-bottom-color:#000000;border-bottom-width:1px;" class="ctr"> {!sd.Name}</td>

<td style="border-bottom:solid;border-bottom-color:#000000;border-bottom-width:1px;" class="ctr">${!sd.Site__r.Name}</td></tr>

<apex:repeat var="et" value="{!Account.Bids_Sent4__r.Bid_Deliverables__r}"  >
<tr>
<td style="border-bottom:solid;border-bottom-color:#000000;border-bottom-width:1px;" class="ctr"> {!et.Scope__c} {!et.Increment__c}</td>

<td style="border-bottom:solid;border-bottom-color:#000000;border-bottom-width:1px;" class="ctr">${!et.Price__c}</td>

<td style="border-bottom:solid;border-bottom-color:#000000;border-bottom-width:1px;" class="ctr">${!et.Bid_Name__r.Name}</td>
</tr>
  </apex:repeat>
</apex:repeat>
</table></html>
</form>
</apex:page>




 
Best Answer chosen by BobP
BobPBobP
Thank you very much Sunil for your patience. I did update the [sd.Id] to Name, but it was still giving me the error. 
Once I created a button on the Account object and tested it, the codes works. The finish code is working.
 
Public Class AccountExtensionController{
   private Account acc;
   public List<Bids_Sent__c> bidsList {get;set;}
   public Map<String,List<Site_Bid_Details__c>>  bidsMap {get;set;}
   public AccountExtensionController(ApexPages.StandardController sc){
       acc = (Account)sc.getRecord();
       bidsList = new List<Bids_Sent__c>();
       bidsList = [SELECT Id,Name,Site__r.Name,Customer__r.Name  FROM Bids_Sent__c WHERE Awarded__c =: acc.Id];
    Set<Id> bidId = new  Set<Id>();  
    for(Bids_Sent__c bs : bidsList){
       bidId.add(bs.Id);
    }
     
    bidsMap = new Map<String,List<Site_Bid_Details__c>> ();
    for(Site_Bid_Details__c bd : [SELECT Id, Bid_Name__r.Name,Increment__c,Price__c,Scope__c FROM Site_Bid_Details__c WHERE Bid_Name__c IN : bidId]){
        if(bidsMap.containsKey(bd.Bid_Name__r.Name)){
           bidsMap.get(bd.Bid_Name__r.Name).add(bd);
        }
        else{
            bidsMap.put(bd.Bid_Name__r.Name,new List<Site_Bid_Details__c>{bd});
        }
    } 

}

}

 

All Answers

Sunil SirangiSunil Sirangi

Hi @Bobp,

We need to use an extension class to query those records and use them in the visual force page. You can use below extension class.

Public Class AccountExtensionController{
   public List<Bids_Sent4__c> bidsList {get;set;}
   public Map<Bids_Sent4__c,List<Bid_Deliverables__c> bidsMap {get;set;}
   public AccountExtensionController(ApexPages.StandarcController sc){
       bidsList = new List<Bids_Sent4__c>();
       bidsList = [SELECT Id FROM Bids_Sent4__c WHERE Account__c =: sc.getRecordId() ];
    Set<Id> bidId = new  Set<Id>();  
    for(Bids_Sent4__c bs : bidsList){
       bidId.add(bs.Id);
    }
     
    bidsMap = new Map<Bids_Sent4__c,List<Bid_Deliverables__c>();
    for(Bid_Deliverables__c bd : [SELECT Id,Bids_Sent4__c FROM Bid_Deliverables__c WHERE Bids_Sent4__c IN : bidId){
        if(bidsMap.containsKey(bd.Bids_Sent4__c)){
           bidsMap.get(bd.Bids_Sent4__c).add(bd);
        }
        else{
            bidsMap.put(bd.Bids_Sent4__c,new List<Bid_Deliverables__c>{bd});
        }
    } 

}

}
 

Now use the bidsList & bidsMap in your visual force page to display the values. Please do add null checks to the above controller. Let me know if this helps.

BobPBobP
Hi Sunil,

I am getting a error "Error: Compile Error: Unexpected token '<'. at line 3 column 14"
Sunil SirangiSunil Sirangi
Public Class AccountExtensionController{
   public List<Bids_Sent4__c> bidsList {get;set;}
   public Map<Bids_Sent4__c,List<Bid_Deliverables__c>> bidsMap {get;set;}
   public AccountExtensionController(ApexPages.StandarcController sc){
       bidsList = new List<Bids_Sent4__c>();
       bidsList = [SELECT Id FROM Bids_Sent4__c WHERE Account__c =: sc.getRecordId() ];
    Set<Id> bidId = new  Set<Id>();  
    for(Bids_Sent4__c bs : bidsList){
       bidId.add(bs.Id);
    }
     
    bidsMap = new Map<Bids_Sent4__c,List<Bid_Deliverables__c>();
    for(Bid_Deliverables__c bd : [SELECT Id,Bids_Sent4__c FROM Bid_Deliverables__c WHERE Bids_Sent4__c IN : bidId){
        if(bidsMap.containsKey(bd.Bids_Sent4__c)){
           bidsMap.get(bd.Bids_Sent4__c).add(bd);
        }
        else{
            bidsMap.put(bd.Bids_Sent4__c,new List<Bid_Deliverables__c>{bd});
        }
    } 

}

}

I used notepad to write the code and did not check for compilation errors. Please use the above code now. If it solves the issue please mark this best answer. Thanks.
BobPBobP
Hi Sunil,

 I fixed a couple of syntax errors, but i am getting the following error. 

"Error: Compile Error: Invalid type: Bids_Sent4__c at line 2 column 31"

 
Public Class AccountExtensionController{
   public List<Bids_Sent4__c> bidsList {get;set;}
   public Map<Bids_Sent4__c,List<Bid_Deliverables__c>> bidsMap {get;set;}
   public AccountExtensionController(ApexPages.StandarcController sc){
       bidsList = new List<Bids_Sent4__c>();
       bidsList = [SELECT Id FROM Bids_Sent4__c WHERE Account__c =: sc.getRecordId() ];
    Set<Id> bidId = new  Set<Id>();  
    for(Bids_Sent4__c bs : bidsList){
       bidId.add(bs.Id);
    }
     
    bidsMap = new Map<Bids_Sent4__c,List<Bid_Deliverables__c>>();
    for(Bid_Deliverables__c bd : [SELECT Id,Bids_Sent4__c FROM Bid_Deliverables__c WHERE Bids_Sent4__c IN : bidId]){
        if(bidsMap.containsKey(bd.Bids_Sent4__c)){
           bidsMap.get(bd.Bids_Sent4__c).add(bd);
        }
        else{
            bidsMap.put(bd.Bids_Sent4__c,new List<Bid_Deliverables__c>{bd});
        }
    } 

}

}

 
Sunil SirangiSunil Sirangi
Bids_Sent4__c & Bid_Deliverables__c are the same as the object API names you have provided in your code. Can you check in your instance whether those API names are correct or not.
BobPBobP
Bids_Sent4__c & Bid_Deliverables__c are lookup field child relationship name. the actually object names are Bids_Sent__c & Bid_Name__c. Sorry about that. 

I'm getting a error on line 6 too
Error: Compile Error: Method does not exist or incorrect signature: void getRecordId() from the type ApexPages.StandardController at line 6 column 70


 
Public Class AccountExtensionController{
   public List<Bids_Sent__c> bidsList {get;set;}
   public Map<Bids_Sent__c,List<Site_Bid_Details__c>> bidsMap {get;set;}
   public AccountExtensionController(ApexPages.StandardController sc){
       bidsList = new List<Bids_Sent__c>();
       bidsList = [SELECT Id FROM Bids_Sent__c WHERE Account__c =:sc.getRecordId()];
    Set<Id> bidId = new  Set<Id>();  
    for(Bids_Sent__c bs : bidsList){
       bidId.add(bs.Id);
    }
     
    bidsMap = new Map<Bids_Sent__c,List<Bid_Deliverables__c>>();
    for(Bid_Deliverables__c bd : [SELECT Id,Bids_Sent__c FROM Bid_Deliverables__c WHERE Bids_Sent__c IN : bidId]){
        if(bidsMap.containsKey(bd.Bids_Sent__c)){
           bidsMap.get(bd.Bids_Sent__c).add(bd);
        }
        else{
            bidsMap.put(bd.Bids_Sent__c,new List<Bid_Deliverables__c>{bd});
        }
    } 

}

}

 
Sunil SirangiSunil Sirangi
Public Class AccountExtensionController{
   private Account acc;
   public List<Bids_Sent__c> bidsList {get;set;}
   public Map<Bids_Sent__c,List<Site_Bid_Details__c>> bidsMap {get;set;}
   public AccountExtensionController(ApexPages.StandardController sc){
       acc = (Account)sc.getRecord();
       bidsList = new List<Bids_Sent__c>();
       bidsList = [SELECT Id FROM Bids_Sent__c WHERE Account__c =: acc.Id];
    Set<Id> bidId = new  Set<Id>();  
    for(Bids_Sent__c bs : bidsList){
       bidId.add(bs.Id);
    }
     
    bidsMap = new Map<Bids_Sent__c,List<Bid_Deliverables__c>>();
    for(Bid_Deliverables__c bd : [SELECT Id,Bids_Sent__c FROM Bid_Deliverables__c WHERE Bids_Sent__c IN : bidId]){
        if(bidsMap.containsKey(bd.Bids_Sent__c)){
           bidsMap.get(bd.Bids_Sent__c).add(bd);
        }
        else{
            bidsMap.put(bd.Bids_Sent__c,new List<Bid_Deliverables__c>{bd});
        }
    } 

}

}
Try this now
 
BobPBobP
Hello I updated because i had other errors. when I try to compile this code it gives me the following error.

Error: Compile Error:
SELECT Id, Bid_Name__c,Bids_Sent__c FROM Site_Bid_Details__c
^
ERROR at Row:1:Column:24
No such column 'Bids_Sent__c' on entity 'Site_Bid_Details__c'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names. at line 15 column 34
Public Class AccountExtensionController{
   private Account acc;
   public List<Bids_Sent__c> bidsList {get;set;}
   public Map<Bids_Sent__c,List<Site_Bid_Details__c>> bidsMap {get;set;}
   public AccountExtensionController(ApexPages.StandardController sc){
       acc = (Account)sc.getRecord();
       bidsList = new List<Bids_Sent__c>();
       bidsList = [SELECT Id FROM Bids_Sent__c WHERE Awarded__c =: acc.Id];
    Set<Id> bidId = new  Set<Id>();  
    for(Bids_Sent__c bs : bidsList){
       bidId.add(bs.Id);
    }
     
    bidsMap = new Map<Bids_Sent__c,List<Site_Bid_Details__c>>();
    for(Site_Bid_Details__c bd : [SELECT Id, Bid_Name__c,Bids_Sent__c FROM Site_Bid_Details__c WHERE Bid_Name__c IN : bidId]){
        if(bidsMap.containsKey(bd.Bids_Sent__c)){
           bidsMap.get(bd.Bid_Name__c).add(bd);
        }
        else{
            bidsMap.put(bd.Bid_Name__c,new List<Site_Bid_Details__c>{bd});
        }
    } 

}

}
Sunil SirangiSunil Sirangi
Are you sure you have this field "Bids_Sent__c" on the object Site_Bid_Details__c.
Sunil SirangiSunil Sirangi
And also update your map definition to Map<String,List<Site_Bid_Details__c>> instead of Map<Bids_Sent__c,List<Site_Bid_Details__c>>
BobPBobP
Bids_Sent__c is the parent object of the Site_Bid_Details__c object   Bid_Name__c is a custom  lookup field on the Site_Bid_Details__c obejct 
BobPBobP
Hellow Sunil,
Thank you so much for your help 
I have fixed the class and was able to save it.  Now I just need to add it to my visualforce page. Do you know how I would add the class to the repeat components on the vf page?
 
<apex:repeat var="sd" value="{!Account.Bids_Sent4__r}">
                   
<tr>
<td style="border-bottom:solid;border-bottom-color:#000000;border-bottom-width:1px;" class="ctr"> {!sd.Name}</td>

<td style="border-bottom:solid;border-bottom-color:#000000;border-bottom-width:1px;" class="ctr">${!sd.Site__r.Name}</td></tr>

<apex:repeat var="et" value="{!Account.Bids_Sent4__r.Bid_Deliverables__r}"  >
<tr>
<td style="border-bottom:solid;border-bottom-color:#000000;border-bottom-width:1px;" class="ctr"> {!et.Scope__c} {!et.Increment__c}</td>

<td style="border-bottom:solid;border-bottom-color:#000000;border-bottom-width:1px;" class="ctr">${!et.Price__c}</td>

<td style="border-bottom:solid;border-bottom-color:#000000;border-bottom-width:1px;" class="ctr">${!et.Bid_Name__r.Name}</td>
</tr>
  </apex:repeat>
</apex:repeat>


 
Public Class AccountExtensionController{
   private Account acc;
   public List<Bids_Sent__c> bidsList {get;set;}
   public Map<String,List<Site_Bid_Details__c>>  bidsMap {get;set;}
   public AccountExtensionController(ApexPages.StandardController sc){
       acc = (Account)sc.getRecord();
       bidsList = new List<Bids_Sent__c>();
       bidsList = [SELECT Id FROM Bids_Sent__c WHERE Awarded__c =: acc.Id];
    Set<Id> bidId = new  Set<Id>();  
    for(Bids_Sent__c bs : bidsList){
       bidId.add(bs.Id);
    }
     
    bidsMap = new Map<String,List<Site_Bid_Details__c>> ();
    for(Site_Bid_Details__c bd : [SELECT Id, Bid_Name__c FROM Site_Bid_Details__c WHERE Bid_Name__c IN : bidId]){
        if(bidsMap.containsKey(bd.Bid_Name__c)){
           bidsMap.get(bd.Bid_Name__c).add(bd);
        }
        else{
            bidsMap.put(bd.Bid_Name__c,new List<Site_Bid_Details__c>{bd});
        }
    } 

}

}

 
Sunil SirangiSunil Sirangi
Visualforce Page Code
<apex:repeat var="sd" value="{!bidsList}">
                   
<tr>
<td style="border-bottom:solid;border-bottom-color:#000000;border-bottom-width:1px;" class="ctr"> {!sd.Name}</td>

<td style="border-bottom:solid;border-bottom-color:#000000;border-bottom-width:1px;" class="ctr">${!sd.Site__r.Name}</td></tr>

<apex:repeat var="et" value="{!bidsMap[sd.Name]}"  >
<tr>
<td style="border-bottom:solid;border-bottom-color:#000000;border-bottom-width:1px;" class="ctr"> {!et.Scope__c} {!et.Increment__c}</td>

<td style="border-bottom:solid;border-bottom-color:#000000;border-bottom-width:1px;" class="ctr">${!et.Price__c}</td>

<td style="border-bottom:solid;border-bottom-color:#000000;border-bottom-width:1px;" class="ctr">${!et.Bid_Name__r.Name}</td>
</tr>
  </apex:repeat>
</apex:repeat>
Apex Class
Public Class AccountExtensionController{
   private Account acc;
   public List<Bids_Sent__c> bidsList {get;set;}
   public Map<String,List<Site_Bid_Details__c>>  bidsMap {get;set;}
   public AccountExtensionController(ApexPages.StandardController sc){
       acc = (Account)sc.getRecord();
       bidsList = new List<Bids_Sent__c>();
       bidsList = [SELECT Id,Name,Site__r.Name FROM Bids_Sent__c WHERE Awarded__c =: acc.Id];
    Set<Id> bidId = new  Set<Id>();  
    for(Bids_Sent__c bs : bidsList){
       bidId.add(bs.Id);
    }
     
    bidsMap = new Map<String,List<Site_Bid_Details__c>> ();
    for(Site_Bid_Details__c bd : [SELECT Id,Bids_Sent__r.Name,Bid_Name__c,Increment__c,Price__c FROM Site_Bid_Details__c WHERE Bid_Name__c IN : bidId]){
        if(bidsMap.containsKey(bd.Bids_Sent__r.Name)){
           bidsMap.get(bd.Bids_Sent__r.Name).add(bd);
        }
        else{
            bidsMap.put(bd.Bids_Sent__r.Name,new List<Site_Bid_Details__c>{bd});
        }
    } 

}

}

Please use the above update code. if you get any error regarding the field not present or field missing error, Please update code to reflect the correct names.

If it works please mark this as best answer.
BobPBobP
Hi Sunil,

I've tried to update the visualforce page in the bidsmap repeat section, but no matter what i tried I a am getting the following error.

"Visualforce Error
Help for this Page
Map key a0Mf4000009Yd63EAC not found in map
Error is in expression '{!bidsMap[sd.Id]}' in component <apex:repeat> in page test_awarded"

 
<apex:page standardcontroller="Account"  extensions="AccountExtensionController"  standardstylesheets="false" showheader="false" applyhtmltag="false">
<form >
<html xmlns="http://www.w3.org/1999/xhtml">
    <body>
    </body>
    
 
   
 
    <table align="center" width="85%" style="font-family: Arial, Helvetica, sans-serif; border-collapse: collapse;  text-align:center;"
               cellpadding="2">
             <apex:repeat var="sd" value="{!bidsList}">
                   
<tr>
<td style="border-bottom:solid;border-bottom-color:#000000;border-bottom-width:1px;" class="ctr"> {!sd.Name}</td>

<td style="border-bottom:solid;border-bottom-color:#000000;border-bottom-width:1px;" class="ctr">${!sd.Site__r.Name}</td></tr>

<apex:repeat var="et" value="{!bidsMap[sd.Id] }"  >
<tr>
<td style="border-bottom:solid;border-bottom-color:#000000;border-bottom-width:1px;" class="ctr"> {!et.Scope__c} {!et.Increment__c}</td>

<td style="border-bottom:solid;border-bottom-color:#000000;border-bottom-width:1px;" class="ctr">${!et.Price__c}</td>

<td style="border-bottom:solid;border-bottom-color:#000000;border-bottom-width:1px;" class="ctr">${!et.Bid_Name__r.Name}</td>
</tr>
  </apex:repeat>

</apex:repeat>
            </table></html>

</form>


</apex:page>

 
Sunil SirangiSunil Sirangi
In your vf page where you mentioned bidsmap[sd.Id] use bidsMap[sd.Name]
BobPBobP
Thank you very much Sunil for your patience. I did update the [sd.Id] to Name, but it was still giving me the error. 
Once I created a button on the Account object and tested it, the codes works. The finish code is working.
 
Public Class AccountExtensionController{
   private Account acc;
   public List<Bids_Sent__c> bidsList {get;set;}
   public Map<String,List<Site_Bid_Details__c>>  bidsMap {get;set;}
   public AccountExtensionController(ApexPages.StandardController sc){
       acc = (Account)sc.getRecord();
       bidsList = new List<Bids_Sent__c>();
       bidsList = [SELECT Id,Name,Site__r.Name,Customer__r.Name  FROM Bids_Sent__c WHERE Awarded__c =: acc.Id];
    Set<Id> bidId = new  Set<Id>();  
    for(Bids_Sent__c bs : bidsList){
       bidId.add(bs.Id);
    }
     
    bidsMap = new Map<String,List<Site_Bid_Details__c>> ();
    for(Site_Bid_Details__c bd : [SELECT Id, Bid_Name__r.Name,Increment__c,Price__c,Scope__c FROM Site_Bid_Details__c WHERE Bid_Name__c IN : bidId]){
        if(bidsMap.containsKey(bd.Bid_Name__r.Name)){
           bidsMap.get(bd.Bid_Name__r.Name).add(bd);
        }
        else{
            bidsMap.put(bd.Bid_Name__r.Name,new List<Site_Bid_Details__c>{bd});
        }
    } 

}

}

 
This was selected as the best answer