0

In my Product Object there is a list of ProductMatrices. I want to total sum of matrices field. So for that i used Aggregate soql. But its not showing aggregate result.

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

totalSummaryMatrix = [Select Id,Product__c, SUM(Total_Sale__c)totalSalesSum, SUM(Order_Recieved__c)totalOrderSum, AVG(Sell_Through__c)average From Product_Matrix__c Where Product__c IN : prodIdsList Group By Id,Product__c];
System.debug('totalSummaryMatrix+++==='+totalSummaryMatrix);

please someone help me.

  • When you say not showing, how are you confirming it? – Jayant Das Feb 4 at 12:07
  • by using debug log – Hennry Feb 4 at 12:08
  • Did you get a Product_Matrix__c list depend on prodIdsList – vignesh Feb 4 at 12:08
  • Printing the list in debug will not give you the complete details. You should verify by printing the size of the list and/or iterating through the list to see the results. Also make sure that the running user has access to the records. – Jayant Das Feb 4 at 12:10
  • yes Product_Matrix__c list is depend on prodIdsList – Hennry Feb 4 at 12:19
5

It's not giving you a sum because your first grouping is on the Id of the Product_Matrix__c:

totalSummaryMatrix = [
    Select Id,Product__c, SUM(Total_Sale__c)totalSalesSum, SUM(Order_Recieved__c)totalOrderSum, AVG(Sell_Through__c)average 
    From Product_Matrix__c 
    Where Product__c IN : prodIdsList 
    Group By Id,Product__c
];

Each of your groups therefore has a size of one, since each record has a different Id, and the sum is coming back simply as the value of the field on that one object.

You should remove GROUP BY Id and only group by the field that defines the scope of each summary line item, which appears to be Product__c.

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.