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
Nithya tsNithya ts 

How to query the total number of product associated with opportunity?

AbhimanyuAbhimanyu
Try This Query,
Select PriceBookEntry.Product2.Id,PriceBookEntry.Product2.Name from OpportunityLineItem where OpportunityId= :OppId
 
Ajay K DubediAjay K Dubedi
Hi Nithya,
Try the below query, it may be helpful for you:
List<Opportunity> oppList = [SELECT Id, Name, Account.Name,(SELECT Quantity, UnitPrice, TotalPrice,PricebookEntry.Name, PricebookEntry.Product2.Family FROM OpportunityLineItems) FROM Opportunity WHERE Id = :'0060o00001D774JAAR'];
System.debug('oppList-->'+oppList);

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi