I'm trying to join two standard objects, and a custom object. I need to join OpportunityLineItem
, Opportunity
, and MyObject
. All tables have references to each other.
MyObject
has OpportunityLineItemID__c
which points back to OpportunityLineItem
's Id
. The OpportunityLineItem
has OpportunityId
which maps back to Opportunity
's Id
.
In standard SQL I'd write this as:
SELECT *
FROM OpportunityLineItem as oli
join Opportunity as o
on oli.OpportunityId = o.id
join myobject as m
on m.id = oli.id
where ...
I tried with the __r
notation but I get an error about the relations:
Didn't understand relationship 'myobject__r' in field path. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names.
My SQOL attempt:
SELECT myobject__r.fieldIwantInThisTable
FROM OpportunityLineItem where ....
I'm leaving out the Opportunity
for MVCE.
OpportunityLineItem
have a relationship field that points to yourMyObject__c
object? I answered a similar question here about 2.5 years ago that you might find helpful.OpportunityLineItem
does not have a custom field that maps toMyObject__c
. Theid
field in that table maps toOpportunityLineItemID__c
inmyobject__c
though. Perhaps I need to run thefrom myobject__c
rather thanOpportunityLineItem
and then useOpportunityLineItem__r...
for the fields I want?