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

How do you Group By in Apex?

Does anyone know how do i group by Product2__r.Family in this statement in Apex Code? In the end I want to create a VF Page that would be in a PageTableBlock to break it down by Family withSubtotal..


void queryQuoteLines(id id) { quote = [Select s.Opportunity__r.Pricebook2Id, Quote_Amount_rollup__c,LastmodifiedDate, (Select Unit_Price__c, Unit_Net_Price__c, ServiceDate__c, Sales_Discount__c,CurrencyIsoCode, Quote__c, Qty_Ordered__c, Product2__c, Product2__r.Family, Product2__r.Name, Product_Family__c,Name, Id, Ext_Price__c, Ext_Net_Price__c, Ext_Price_tmp__c, Description__c From Quote_Lines__r order by name ), (Select Title, Body, CreatedDate From Notes), s.Opportunity__r.HasOpportunityLineItem, s.Opportunity__r.Sub_Partner__c,s.Opportunity__r.Name, s.Name,s.Partner_Direct__c, s.Opportunity__r.Id, s.Opportunity__r.License__c,s.Opportunity__c,s.Valid_Until__c From SFDC_520_Quote__c s where = :id limit 1];







There is no group by function in SOQL(grrrr). You can vote for the idea here: You would have to use some trickery to simulate this functionality eg. create a list per product family and display a table for each. You could even make them look like one table by turning the column headers off.


Sorry buddy,