5

I queried quote from opportunity using child to parent relationship. I need to get the all QuoteLineItem records from quote using same query. Could anybody help on this.

Soql Query:

List<id> ids = new List<id>();
List<Opportunity> opp = [SELECT Id, 
                                Accountid, 
                                Name, 
                                StageName,
                                (SELECT Id, Name, OpportunityId FROM Quotes) 
                         FROM Opportunity 
                         WHERE Id=:ids]

I need to get the all QuoteLineItem records from quote using same query. How is it possible.

3

Unfortunately you can't include a subquery in a subquery. Therefore, you can't query opportunities, with quotes and quote line items. However, as an easy work around you can query quotes, with the opportunity information, and the quote line items. That works like this:

List<Quote> quotes = [SELECT Id,
                             Name, 
                             Accountid,
                             OpportunityId,
                             Opportunity.Name, 
                             Opportunity.StageName,
                             (SELECT Id FROM QuoteLineItems) 
                         FROM Quote 
                         WHERE OpportunityId IN :ids]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.