Search code examples
salesforcesoql

Retrieving Contact.Email, Opportunity.Name and OpportunityLineItem.Quantity in one query


I'm trying to retrieve Contact.Email, Opportunity.Name and OpportunityLineItem.Quantity in a single SOQL query. Is this possible? If so, how?

My query is:

Select Opportunity.Id, Opportunity.Name, Contact.Email, (Select Quantity From OpportunityLineItem) From OpportunityContactRole Limit 10

My main objective is to get elements from OpportunityContactRole and OpportunityLineItem in a single query.


Solution

  • You were close :)

    SELECT Id, Name,
        (SELECT Quantity FROM OpportunityLineItems),
        (SELECT Contact.Email FROM OpportunityContactRoles)
    FROM Opportunity