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
YukinonYukinon 

3 Lookup Relationship SOQL Query

I want to get the data from opportunity product and the opportunity name where that product is currently in but I can only get the opportunity Id since opportunity is in a lookup relationship with account.

Any tips on how can I get OpportunityProduct.Name and Opportunity.Name from Opportunity, Opportunity Product, and Account Object?
Best Answer chosen by Yukinon
AnkaiahAnkaiah (Salesforce Developers) 
Hi Angel,

try with below query.
SELECT Id, Name, Account.Name, 
  (SELECT Quantity, UnitPrice, TotalPrice, 
   PricebookEntry.Name, PricebookEntry.Product2.Family FROM 
   OpportunityLineItems) 
FROM Opportunity

If this helps, Please mark it as best answer.

Thanks!!