1

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.

2 Answers 2

5

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]
0
0

You can do this with SalesForce CPQ, taking the quote line id directly from the opportunity product line:

SELECT 
ID,
SBQQ__PrimaryQuote__c,
Amount,

(
    SELECT
        Id,
        SBQQ__QuoteLine__r.SBQQ__NetPrice__c,
        SBQQ__QuoteLine__r.SBQQ__Quantity__c,
        SBQQ__QuoteLine__r.SBQQ__NetTotal__c
    FROM OpportunityLineItems 
    ORDER BY SBQQ__QuoteLine__r.sbqq__number__c
) 
FROM Opportunity 
LIMIT 1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .