Showing posts with label Aggregate query has too many rows for direct assignment. Show all posts
Showing posts with label Aggregate query has too many rows for direct assignment. Show all posts

Jul 22, 2022

|FATAL_ERROR|System.QueryException: Aggregate query has too many rows for direct assignment, use FOR loop


Issue: Unable to add new lines/Products if already added more than 100

Backend debug log
|FATAL_ERROR|System.QueryException: Aggregate query has too many rows for direct assignment, use FOR loop

 

The solution provided here: Salesforce Developers

 

1 for(sbqq__quote__c qt : [SELECT Id,Quote_Type__c,Special_Freight_Rate__c,Consumables_Only__c, 2 Company_Region__c,Country_code__c,Comp_Reg_Text__c, 3 (SELECT Id,SBQQ__AdditionalDiscountAmount__c,SBQQ__ListPrice__c,SBQQ__ProductCode__c, 4 Product_Group__c,Product_Type__c,SBQQ__Optional__c,SBQQ__NetTotal__c,SBQQ__NetPrice__c, 5 SBQQ__EffectiveQuantity__c,Dangerous_Goods__c,Instrument_item__c,Consumable_item__c, 6 Article_Type_Number__c,SBQQ__Quantity__c,Trade_Name__c,SBQQ__Quote__c,Article_Type__c, 7 SBQQ__Quote__r.Country_Code__c,SBQQ__Product__r.Weight__c, SBQQ__Product__r.Net_Weight__c, 8 SBQQ__Product__r.Weight_unit__c, CurrencyIsoCode 9 FROM SBQQ__LineItems__r order by SBQQ__Number__c ASC) 10 FROM sbqq__quote__c WHERE Id in :quoteIds]) 11 { 12 /************** prevoius code ************ 13 //QuoteToLineMap.put(qt.id,qt.SBQQ__LineItems__r ); 14 ************************************************/
15 16 /**************** Modified code ******************/ 17 if(!QuoteToLineMap.containsKey(qt.Id)){ 18 QuoteToLineMap.put(qt.id,new List<SBQQ__QuoteLine__c>()); 19 } 20 for(SBQQ__QuoteLine__c insideLine : qt.SBQQ__LineItems__r ){ 21 QuoteToLineMap.get(qt.id).add(insideLine); 22 } 23 24