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
Vidya BhandaryVidya Bhandary 

SOQL __r -> not displaying data although adding a temp field in the object displays that data !

I have a 2 level parent child relationship and I am trying to use  a SOQL query ... SA (child) --> SQ  --> S. There is a one to many relationship between SA to SQ and SQ to S.

When I give a query like this ... I get a response but the last field with 2 relationships does not display anything - only [object Object] [ Am currently just trying in the Developer Console to get my query right ]

Select SA__c.Id, SA__c.Name,
SA__c.SQ__r.Name__c,

SA__c.SQ__r.S__r.Name__c

from SA__c where
SA__c.SQ__r.S__c = 'a0Hi0000009S5jcEAC'

So I checked adding a field like this in the SA object and it gets displayed just fine !!!!
Best Answer chosen by Vidya Bhandary
Peter_sfdcPeter_sfdc
Does the object named 'S' have a custom name field? 

If so...you're right, it is curious that this is not found. 

If not, then my first guess is that you need to drop the __c suffix and select the field as such: 
SQ__r.S__r.name


If neither of those fits, then would you mind furnishing some additional information: 
1. Are you able to execute the query?
2. Are you receiving an error? 
3. What is the error you are receiving? 
4. Does the query execute successfully but not return any value? 

Answering these questions could help with some of the ambiguity of your initial question. 

Finally...just a suggestion...there is no need to explicitly name the object that is being queried in the FROM clause when you select fields. So a more simple form of your query would have been a little easier for me to read: 

SELECT Id, Name, SQ__r.Name__c, SQ__r.S__r.Name__c FROM SA__c WHERE SQ__R.S__c = 'a0Hi0000009S5jcEAC'
 

All Answers

Peter_sfdcPeter_sfdc
Does the object named 'S' have a custom name field? 

If so...you're right, it is curious that this is not found. 

If not, then my first guess is that you need to drop the __c suffix and select the field as such: 
SQ__r.S__r.name


If neither of those fits, then would you mind furnishing some additional information: 
1. Are you able to execute the query?
2. Are you receiving an error? 
3. What is the error you are receiving? 
4. Does the query execute successfully but not return any value? 

Answering these questions could help with some of the ambiguity of your initial question. 

Finally...just a suggestion...there is no need to explicitly name the object that is being queried in the FROM clause when you select fields. So a more simple form of your query would have been a little easier for me to read: 

SELECT Id, Name, SQ__r.Name__c, SQ__r.S__r.Name__c FROM SA__c WHERE SQ__R.S__c = 'a0Hi0000009S5jcEAC'
 
This was selected as the best answer
Vidya BhandaryVidya Bhandary
Hi,

Yes I have a custom field called Name__c  in my object and it is not able to display that. The query runs but it shows [object object] in the result field.
But then the query returns the same thing for all items for e.g.

SQ__r.S__r.Name
SQ__r.S__r.Id
SQ__r.S__r.Name__c
SQ__r.S__r.Score__c
etc

So far only giving S__c which is the API name of the object gives me the Salesforce ID of that - but I want the values.

So when I give the following in the query

SA__c.SQ__r.S__c

I get the ID.

>>>>

Thank you for the info on the query - will simplify it. 
Vidya BhandaryVidya Bhandary
Finally this got resolved. The problem is with the Query Editor in Force.com Developer console. It is not able to handle this query ( or perhaps is not able to parse the return value). I ran this query in  workbench and it returned the results properly !!! 

So there is a limitation here ! grandchild to grandparent access does not get displayed in the query editor I guess.