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
Brendan Walton 2Brendan Walton 2 

SOQL - Query Session date from Junction Object

I have the following:
User-added image

Attempting the following query:
SELECT Id,(SELECT Session_Date__c FROM Session__r) FROM Session_Speaker__c

Returns:
Id,(Select Session_Date__c FROM Session__r) FROM Session_Speaker__c
                                                    ^
ERROR at Row:1:Column:40
Didn't understand relationship 'Session__r' in FROM part of query call. 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.

I'm not sure what I'm doing wrong. I'm very clearly inserting the __r as the error message suggests. The Session Speaker object clearly has the relationship I'm attempting to utilize. The session object clearly has the date field I'm attempting to query.
Best Answer chosen by Brendan Walton 2
William TranWilliam Tran
Try this:

SELECT Id, session__r.Session_Date__c FROM Session_Speaker__c

when you go up, you can use dot notation

thx.

All Answers

William TranWilliam Tran
Try this:

SELECT Id, session__r.Session_Date__c FROM Session_Speaker__c

when you go up, you can use dot notation

thx.
This was selected as the best answer
Neetu_BansalNeetu_Bansal
Hi Brendan,

As Session speaker is junction, you can't do inner query, use this instead:
SELECT Id, Sessions__r.Session_Date__c FROM Session_Speaker__c

Thanks,
Neetu
Brendan Walton 2Brendan Walton 2

So:
Detail to master = Dot notation

Master to detail = Inner query

Correct?

William TranWilliam Tran
Yes:

Detail to master (go up to parent) = Dot notation

Master to detail (go down to child) = Inner query (using the child relationship name, which you define which usual includes an 's')

Thx
Brendan Walton 2Brendan Walton 2
I am able to get it to work with the Dot notation; however, I'm not getting the reverse to work:

SELECT Id, (SELECT Id FROM Session_Speaker__r) FROM Session__c
 
Neetu_BansalNeetu_Bansal
Hi Brendan,

Use plural name like:
SELECT Id, (SELECT Id FROM Session_Speakers__r) FROM Session__c

Thanks,
Neetu
Brendan Walton 2Brendan Walton 2

I tried that as well:

SELECT Id, (SELECT Id FROM Session_Speakers__r) FROM Session__c
Returns the same error message

Brendan Walton 2Brendan Walton 2
I found a typo in my objects plural name, I fixed it but the issue still persists.
Neetu_BansalNeetu_Bansal
Do you know what is the child relationship name for this, may be its different that Session_Speakers__r.

Thanks,
Neetu
Brendan Walton 2Brendan Walton 2
There is no relationship under the Custom Fields and Relationships on the session object. I assume this is because Session Speakers is a junction object.
William TranWilliam Tran
This should work 

SELECT Id, (SELECT Id FROM Session_Speakers__r) FROM Session__c

assuming that's the child relationship name you gave it:


Go to the session object and verify:

Master-Detail Options

Related To Session                     Child Relationship Name Session_Speakers
Brendan Walton 2Brendan Walton 2

It was the Child relationship name on the Session_Speakers object that had the same type from the Plural name on the same object.
Thanks William/Neetu you guys have been extremely helpful.

For the best anwer, I'm going to pick the one that most directly answered my original post; however, since you both posted the same answer, I'm going to pick the first person to post it. I feel that's the fairest way; however, I'd like to restate, you were both very helpful. Thank you so much.