0

I have an Object Called Container__c with a child called Article__Container__c. I create a visualforce page to display all child with an Extension Controller. But when i Hit the button on the layout page it display all the child in the database not the ones related to the specific parent record.

//Extention Controller

public class RgrReportControllerExt {
      public List<AggregateResult> allproduct{get;set;}
      public RgrReportControllerExt(ApexPages.StandardController controller) {

      allproduct = [
      SELECT UM__c uom,SUM(Number__c)qtyReceived,  SUM(Quantity__c)qtyPaking,  
      SUM(PrimaryDiscrepency__c)Discrep FROM Articles_Containers__c    
      GROUP BY  UM__c 
      ORDER BY  UM__c limit 1000];    
}
}

// portion of my VF Page
<apex:page RenderAs="PDF" showHeader="false" sidebar="false"  applyBodyTag="false" standardStylesheets="True" standardController="Container__c" Extensions="RgrReportControllerExt">

<b> Description of Goods</b> : <u>{!Container__c.Description__c}</u> <br/>
 (Descripción de bienes) <br/> <br/>

 <div class="firstBlock" >        
            <div class ="SubfirstBlock">     
                <div>
                    <table style="width:100%;border-collapse: collapse; border: 0.5px solid black;"> 
                             <tr >
                                     <th>UoM</th> 
                                     <th>Expected</th>
                                     <th>Actual</th>
                                     <th>Descrepencies</th>  
                             </tr> 

                                  <apex:repeat value="{!allproduct}" var="row">
                                    <tr >
                                      <td>{!row['uom']}</td>
                                      <td>{!row['qtyPaking']}</td>
                                      <td>{!row['qtyReceived']}</td>
                                      <td>{!row['Discrep']}</td> 
                                    </tr>
                                </apex:repeat>
                      </table>   
                </div>   
           </div>

            <div class ="SubfirstBlock">
                <div>

                </div> 
            </div>

            <div class ="SubfirstBlock">
                <div>

                </div>            
            </div>   
    </div>
</apex:page>

1 Answer 1

0

For that you will have to filter your AggregateResult with Container__c's Id, you can use controller.getId()to do so.

This is how your apex class should look like

public class RgrReportControllerExt { 
    public List<AggregateResult> allproduct{get;set;} 

    public RgrReportControllerExt(ApexPages.StandardController controller) { 
        allproduct = [SELECT UM__c uom,SUM(Number__c)qtyReceived, SUM(Quantity__c)qtyPaking, SUM(PrimaryDiscrepency__c)Discrep FROM Articles_Containers__c 
                            Where Container__c = :controller.getId()
                            GROUP BY UM__c ORDER BY UM__c limit 1000]; 
    } 
}

You will have to replace Container__c in the where clause in SOQL with your relationship field name.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .