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
Girbson Bijou 7Girbson Bijou 7 

Aggregate result error message

Help please,  
 The erro message is List has more than 1 row for assignment to SObject error
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['onHand']}</td>  
    <td>{!a.['Pending']}</td>
    <td>{!a.['avail']}</td>
</tr>
  </apex:repeat> </div>
</apex:page>
Best Answer chosen by Girbson Bijou 7
sfdcMonkey.comsfdcMonkey.com
update your class with below code :
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];

      }

}

Thank, let us know if it helps you  

All Answers

sfdcMonkey.comsfdcMonkey.com
update your class with below code :
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];

      }

}

Thank, let us know if it helps you  
This was selected as the best answer
Girbson Bijou 7Girbson Bijou 7
Thank you so much! It work as Expected