+ Start a Discussion
Nurav1982Nurav1982 

SOQL Quick Question

I have the following 3 custom objects

Parent
Child
GrandChild

GrandChild has a lookup relationship with Child.
Child has a MD relationship with Parent (Parent is Master)

Objective : I want to traverse from grandchild to parent.

select gc.name,c.name,p.name
from grandchild__c g,  g.child__r c,   c.parent__r p

I am getting sample output like below

Name                child__r.Name                      child__r.parent__r.Name
"Test GC"         "Test C"                                   [object Object]

Can anyone tell me why am I getting "[object Object]" instead of the parent's name ???

Subramani_SFDCSubramani_SFDC
can u post ur original code or query???
SRKSRK

Intresting..... So do you look what is the body of this Object is 

like you say that child__r.parent__r.Name return you [object Object] then this object must have some body like a wrapper

beacus as per my understnanding it must return you an string only 

Nurav1982Nurav1982
screenshot

select gc.name,c.name,p.name
from grandchild__c gc,gc.child__r c,c.parent__r p

Hi Subramani,SRK,

Plz take a look at the screenshot and the query and let me know if you need anything.
Subramani_SFDCSubramani_SFDC
From the SFDC doc (as of V27.0):



In each specified relationship, only one level of parent-to-child relationship can be specified in a query. For example, if the FROM clause specifies Account, the SELECT clause can only specify the Contact or other objects at that level. It could not specify a child object of Contact.
Nurav1982Nurav1982
Hi

I tried doing from grandchild to child to parent relationship also but still nothing..but i get [Object Object] only :(

select grandchild__c.id,grandchild__c.name,grandchild__c.child__r.name,grandchild__c.child__r.parent__r.column1__c
from grandchild__c

Also I agree that we have one level traversal when we move from parent to child though.
SRKSRK
did you try the same SOQL in  in Apex and system.debug ??
Nurav1982Nurav1982
Yes
System.debug([select id,name,grandchild__c.child__r.name,grandchild__c.child__r.parent__r.name from grandchild__c]);

Output
15:50:46:072 USER_DEBUG [1]|DEBUG|(GrandChild__c:{Name=TEST lookup, Id=a0G9000000EOWQREA5, Child__c=a099000000NZeC5AAL})

Still no parent name
SRKSRK
And if i do it like this what it shows

List<grandchild__c> TempLst = [select id,name,grandchild__c.child__r.name,grandchild__c.child__r.parent__r.name from grandchild__c];

System.debug('#@!#@#!@#!@$@#@#'+TempLst[0].child__r.name);
System.debug('#@!#@#!@#!@$@#@#'+TempLst[0].grandchild__c.child__r.parent__c);
System.debug('#@!#@#!@#!@$@#@#'+TempLst[0].grandchild__c.child__r.parent__r.name);
Subramani_SFDCSubramani_SFDC
SOQL RELATIONAL QUERYTRY TO RUN THE QUERY USING WORKBENCH....THEN U WILL GET THE NAME.....THERE IS SOME ISSUE IN DEV CONSOLE...THATS Y IT RETURNS OBJECT OBJECT.....