+ Start a Discussion
LeonardLeonard 

Can I query Opportunity, OpportunityLineItem and OpportunityLineItemSchedule in the same query?

How do I query Opportunities, OpportunityLineItems and OpportunityLineItemSchedules in the same query when they don't have a parent / child relationship.
Best Answer chosen by Admin (Salesforce Developers) 
NBlasgenNBlasgen

http://community.salesforce.com/sforce/board/message?message.uid=128604#U128604

 

As that page points out, you can go from Child to Parent (and up more even).  So take the most childish of the 3 and then work your way up the line.

All Answers

NBlasgenNBlasgen

I'm not going to be able to answer this one, but it helps if you describe a little more about what you want.  Write a query that you wish would be able to be executed.  Write the query as one might expect in SQL and then we can see if it can be changed into SOQL.  I personally don't understand what output you're expecting.  If you need all rows from Opportunities, all from OpportunityLineImtes, and all from OppLineItemSch then it can't be done as a single query.  But if you want all lines from OppLineItemSch based on knowing something about the Opp, then something might be able to be done.

 

So please better describe what you want.

LeonardLeonard

In SQL

 

 

SELECT Opportunity.Id, OpportunityLineItem.Id, OpportunityLineItemSchedule.Id FROM Opportunity, OpportunityLineItem, OpportunityLineItemSchedule WHERE Opportunity.HasOpportunityLineItem = 'true' AND OpportunityLineItem.HasRevenueSchedule = 'true' AND Opportunity.Id = '00000000aaaa' AND OpportunityLineItem.OpportunityId = Opportunity.Id AND OpportunityLineItemSchedule.OpportunityLineItemId = OpportunityLineItem.Id

 

 

 

LeonardLeonard
I'm still looking for a good solution to this problem. SOQL seems like a very weak query language.
NBlasgenNBlasgen

http://community.salesforce.com/sforce/board/message?message.uid=128604#U128604

 

As that page points out, you can go from Child to Parent (and up more even).  So take the most childish of the 3 and then work your way up the line.

This was selected as the best answer