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
Bob Poliquin 9Bob Poliquin 9 

Apex Class for Visualforce page to show child records of a child record

I am wondering if I can update my apex class to show child records of a child record from the account object.

I have a custom object Bids_Sent__c of an account standard object. The Bids_Sent__c object has a child object  entitled Site_Bid_Details__c. That custom object has a child object entitled Payments__c.  
My Apex Class below is updated to show Account with Bids_Sent__c ad Site_Bid_Detail__c records on my visualforce pdf. But it does not cover the new custom object Payment__c.  I need this to show those child records to show monthly payments if the Site_Bid Detail__c record meets a certain criteria. I'm not sure how to add this to my current class or if this is possible.  

If anyone could help me with this I would greatly appreciate it. 

 
public with sharing class VF_PrintBidPDF {

private Account acc;
   public List<Bids_Sent__c> bidsList {get;set;}
   public Map<String,List<Site_Bid_Details__c>>  bidsMap {get;set;}
   public Map<String,List<Site_Bid_Details__c>>  sbidsMap {get;set;}
   public VF_PrintBidPDF(ApexPages.StandardController sc){
       acc = (Account)sc.getRecord();
       bidsList = new List<Bids_Sent__c>();
       bidsList = [SELECT Id,Add_to_Schedule_C__c,Customer__r.Service_Agreement_Verbiage__c,Site__r.Service_Agreement_Verbiage__c,Service_Agreement_Verbiage__c,Awarded_Date__c,Site__r.Customer_Location_ID__c,Service_Year__c,Site__r.Customer_Account__r.Name,Name,
        Site__r.Name,Customer__r.Name,Primary_Contact__r.FirstName,Site__r.BillingCity,Site__r.BillingState,Site__r.BillingStreet,Site__r.BillingPostalCode,Site_Customer_Name__c,Customer_Name__c,Contract_Start_Date__c,Contract_End_Date__c FROM Bids_Sent__c WHERE Awarded__c =: acc.Id AND Add_to_Schedule_C__c=true  ];
    
          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,IsSeasonal__c, Bid_Name__r.Name,Site__c,Contract_Start_Month__c,Site__r.Customer_Location_ID__c,Cost__c,Increment__c,
    Total__c,Price__c,Scope__c,Bid_Name__r.Service_Type__c,Number_of_Months__c,Retainer_Fee__c,Monthly_Payment__c,UOM__c,Month_Start_Number__c,Month_End_Number__c, Contract_End_Year__c,IsConEndYear__c,IsZone__c FROM Site_Bid_Details__c WHERE Bid_Name__c IN : bidId]){
        
      if(bidsMap.containsKey(bd.Bid_Name__r.Name)){
          System.debug('CONTAINS KEY: ' + bd.Bid_Name__r.Name);
          bidsMap.get(bd.Bid_Name__r.Name).add(bd);
    }  
              
      else { 
          System.debug('CREATE: ' + bd.Bid_Name__r.Name);
          bidsMap.put(bd.Bid_Name__r.Name,new List<Site_Bid_Details__c>{bd}); 
           }
           
    }
          sbidsMap = new Map<String,List<Site_Bid_Details__c>> ();
    for(Site_Bid_Details__c sbd : [SELECT Id,IsSeasonal__c, Bid_Name__r.Name,Site__c,Contract_Start_Month__c,Site__r.Customer_Location_ID__c,Cost__c,Customer__r.Contract_Month__c,Increment__c,Total__c,
    Price__c,Scope__c,Bid_Name__r.Service_Type__c,Number_of_Months__c,Retainer_Fee__c,Monthly_Payment__c,UOM__c,Month_Start_Number__c,Month_End_Number__c,Contract_End_Year__c,IsConEndYear__c,IsZone__c   FROM Site_Bid_Details__c WHERE Bid_Name__c IN : bidId AND IsSeasonal__c = true]){
        
      if(sbidsMap.containsKey(sbd.Bid_Name__r.Name)){
          System.debug('CONTAINS KEY: ' + sbd.Bid_Name__r.Name);
          sbidsMap.get(sbd.Bid_Name__r.Name).add(sbd);
    } 
      else { 
           System.debug('CREATE: ' + sbd.Bid_Name__r.Name);
           sbidsMap.put(sbd.Bid_Name__r.Name,new List<Site_Bid_Details__c>{sbd}); 
           }
        } 
    }
    
    public VF_PrintBidPDF(ApexPages.StandardSetController controller) {
    }
    
    public VF_PrintBidPDF(){
       String myGeneratedFileName = 'SalesforceScool.pdf';
       Apexpages.currentPage().getHeaders().put('content-disposition', 'attachment; filename='+myGeneratedFilename); 
    }

}









 
ShirishaShirisha (Salesforce Developers) 
Hi Bob,

Greetings!

Can you please try the nested loop to query the child of child records on the same page as mentioned in the below document:

https://success.salesforce.com/answers?id=90630000000DFnaAAG

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future.

Warm Regards,
Shirisha Pathuri