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
Dhara Mahesh 9Dhara Mahesh 9 

Hi,How can we iterate opportunity products group by family

Bhargavi TunuguntlaBhargavi Tunuguntla
Hi Mahesh,

As group is not possible in soql.You can use a map with 'ProductId(product Famil) as key' and value as list of Opportunity Products. --- ​Map<Id,List<OpportunityLineItem> >.

 Map<Id,List<OpportunityLineItem> >  opportunityProductMap=new  Map<Id,List<OpportunityLineItem> >();.

Hope this will be helpful.

Thanks 
Bhargavi.
v varaprasadv varaprasad
Hi Dhara,

Try This : 
 
list<AggregateResult>	agresults = [SELECT count(product2id) pid,Product2.family family FROM OpportunityLineItem group by Product2.family]

for (AggregateResult ar : groupedResults)  {
    System.debug('productids ==:' + ar.get('pid'));
    System.debug('family ==:' + ar.get('family'));
}

Hope this helps you!
If my answer helps resolve your query, please mark it as the 'Best Answer' & upvote it to benefit others.

Thanks
Varaprasad
@For SFDC Support: varaprasad4sfdc@gmail.com
Blog: http://salesforceprasad.blogspot.com/

Salesforce latest interview questions  :
https://www.youtube.com/channel/UCOcam_Hb4KjeBdYJlJWV_ZA?sub_confirmation=1