You need to sign in to do that
Don't have an account?

SOQL Join two custom objects into one result/recordset
Is it possible to join two custom objects in a SOQL statement?
For example I have two objects:
Message__c (Fields: Name, To__c, Originator__c, Body__c)
Originator__c (Fields: Name)
The Originator field in the Message object is a normal lookup. When I do a normal SOQL SELECT in Apex, this returns the Id.
I have tried the examples in the docs which don't seem to work, is it possible to do it with custom objects?
Basically I am trying to achieve the equivalent of this SQL:
The result set would look like:
'Message Name', 'Hi there blah blah', 'MyOriginator1'
For example I have two objects:
Message__c (Fields: Name, To__c, Originator__c, Body__c)
Originator__c (Fields: Name)
The Originator field in the Message object is a normal lookup. When I do a normal SOQL SELECT in Apex, this returns the Id.
I have tried the examples in the docs which don't seem to work, is it possible to do it with custom objects?
Basically I am trying to achieve the equivalent of this SQL:
Code:
SELECT Message.Name, Message.Body, Originator.Name
FROM
Message
LEFT JOIN Originator ON Message.Originator = Originator.Id
The result set would look like:
'Message Name', 'Hi there blah blah', 'MyOriginator1'
Cheers
Chris