I want to construct a SOQL query displaying all Opportunities that are sorted by the Products that are associated to it.
I however have a problem finding out how
Opportunity Products are related.
So far, I can query all closed opportunities by the following SOQL:
SELECT Amount,CloseDate,Name FROM Opportunity WHERE StageName = 'Closed' ORDER BY Amount DESC NULLS LAST
This shows me all Opportunities with Amount and Name. But I would like to also display the related Opportunity Product and sort it by those and sum by Opportunity Product.
Just to show the products for opportunities works like this:
SELECT Name FROM Product2
I just found out that the object is called Product2. But I wonder how to combine the two objects (parent-to-child? child-to-parent? child-to-child?) and have no idea how to exactly find that out.
Do you have advice for me, both specific and more general for creating similar queries?
Edit: I should add that I want to group the results by PriceBookEntry, i.e. I want to see all PriceBook entries and the related opportunities.