coder123
coder123

Reputation: 461

Child to Parent SOQL Query

I need a query between Opportunity and OpportunityLineItem.

OpportunityLineItem has a lookup for Opportunity. Child relationship name is OpportunityLineItems. Opportunity Lookup field is called OpportunityId.

I'm trying the below query but it doesn't work.

select Id,Name,OpportunityId__r.Description from OpportunityLineItem

Also tried:

select Id,Name,OpportunityLineItems__r.Description from OpportunityLineItem

Upvotes: 0

Views: 1483

Answers (1)

eyescream
eyescream

Reputation: 19612

Top-down

SELECT Id, Name, Description,
    (SELECT Id, Name FROM OpportunityLineItems)
FROM Opportunity

Bottom-up

SELECT Id, Name, Opportunity.Name, Opportunity.Description
FROM OpportunityLineItem

Check out the links in https://stackoverflow.com/a/73913839/313628 and https://stackoverflow.com/a/73877986/313628 too

Upvotes: 1

Related Questions