0

Help please, I test the SOQL query in developer Console, and work as expected But, i get error message in the VF

My Controller is:

public class InventoryReport {

     public List<Articles_Containers__c> allproduct{get;set;}

     public InventoryReport() {

    AggregateResult allproduct = [
      SELECT Product_Hiden_Name__c, UM__c ,SUM(On_Hand__c)onHand,  SUM(Pending__c)pending,  SUM(Available__c)avail 
      FROM Articles_Containers__c 
         GROUP BY Product_Hiden_Name__c , UM__c 
         HAVING SUM(On_Hand__c)>0
          ORDER BY Product_Hiden_Name__c, UM__c
      limit 1000];

      }

}

VF Page is:

<apex:page controller="InventoryReport" showHeader="true" RenderAs="PDF">
<div class="table">
       <div class="tableHeader">
              <th>Item</th>
              <th>Unit Of Measure </th>
              <th>On Hand </th>
              <th>Pendig </th>
              <th>Available </th>
      </div>
<apex:repeat value="{!allproduct}" var="a"> <!-- <div class="tablebody"> -->
<tr>
   <td>{!a.Product_Hiden_Name__c }</td>
    <td>{!a.UM__c}</td>
    <td>{!a.On_Hand__c}</td>
    <td>{!a.Pending__c}</td>
    <td>{!a.Available__c}</td>
</tr>
  </apex:repeat> </div>
</apex:page>
2

You're "shadowing" the list "allproduct" in the controller with a local variable by the same name in the constructor. This variable is not a list, so it complains if there's not exactly one row of results. You'll need to change both your controller and Visualforce page.

In your visualforce page, to use an aggregaterseult list, you need to use dynamic field references ['fieldName']. You may need to adjust the field names in the Visualforce page and/or add aliases to the fields you're grouping by.


public class InventoryReport {

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

     public InventoryReport() {

         allproduct = [
      SELECT Product_Hiden_Name__c, UM__c ,SUM(On_Hand__c)onHand,  SUM(Pending__c)pending,  SUM(Available__c)avail 
      FROM Articles_Containers__c 
         GROUP BY Product_Hiden_Name__c , UM__c 
         HAVING SUM(On_Hand__c)>0
          ORDER BY Product_Hiden_Name__c, UM__c
      limit 1000];

      }

}

<apex:repeat value="{!allproduct}" var="a"> <!-- <div class="tablebody"> -->
<tr>
   <td>{!a['expr0']}</td>
    <td>{!a['expr1']}</td>
    <td>{!a['onHand']}</td>
    <td>{!a['pending']}</td>
    <td>{!a['avail']}</td>
</tr>
</apex:repeat>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.