function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
StormConsultingStormConsulting 

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:

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'

SuperfellSuperfell
select name, body__c, originator__r.name from message__c
StormConsultingStormConsulting
Thanks a lot that will save me a lot of headaches in the future.

Cheers
Chris