soql – How to SUM the value of a field and add in map values when I need to group by two fields/keys in map of map
I need to show different table in VF as per Product_Category__c and sum of Volume__c for each Brand_Name__c
Below was my controller code please suggest how to populate sum of Volume__c in below map:
list<Rebate_Goal_Brand__c> rebBrand = new list<Rebate_Goal_Brand__c>([SELECT Brand_Name__c,Product_Category__c ,Name,Volume__c FROM Rebate_Goal_Brand__c where Contract__r.name =:contractId and Contract__r.Sales_Org__r.Sales_Org_Code__c="5191" and Product_Category__c != 'Outros']);
for(Rebate_Goal_Brand__c rB: rebBrand)
{
if(!MapGoals.containsKey(rb.Product_Category__c) ){
MapGoals.put(rb.Product_Category__c, new map<string,string>());
}
MapGoals.get(rb.Product_Category__c).put(rb.Brand_Name__c,string.valueOf(rb.Volume__c));
Read more here: Source link