You need to sign in to do that
Don't have an account?
MDXHiker
SOQL Join
In the opp I have a lookup relationship to a custom object which is not a child.
So on the Opp record there is no related field which specifies the value that is selected on this custom object.
How do I write a join in SOQL to query the values for a given opp ?
If I bring these tables down to SQL Server the query would look something like
SELECT
o.Id [OpportunityId],
gp.CusObj_ID__c [GPID]
FROM Opportunity o
LEFT JOIN CusObj__c gp
ON o.CusObj__c = gp.Id
Thanks
You reference it just as it is in the query. In this case it would be
opp.custobj__r.custObj_Id__c
All Answers
select id, custobj__r.custObj_Id__c from opportunity
see the SOQL section of the API docs.
Thanks Simon.
I have tried that but I get 'Object reference not set to an instance of an object'
Could you please elaborate ? I am testing using sforce explorer and it gives this error.
If I try with a particular opp which has an associated CusObj entry - same results. Maybe I am missing something
You are right. IDE executes this fine and I can see the result in the debug
How do I ref this variaable in the code ?
If I have a query like
Opportunity opp=[SELECT Name, custobj__r.custObj_Id__c FROM Opportunity where Id='xxxxx'];
I would access name as opp.Name. How do I get custObj_id__c?
Thanks
You reference it just as it is in the query. In this case it would be
opp.custobj__r.custObj_Id__c