+ Start a Discussion
nelloCnelloC 

Retrieving relationship query data from dynamic soql

I have a dynamic soql statement like this for example:

 

Sobject relObj;
relObj = Database.query('Select Id, ns__user__c, ns__Distribution_List__r.Name from ns__Distribution_List_User__c where id = \'a0aA0000000aaAAAAA\'');
String listName = String.valueOf(relObj.get('ns__Distribution_List__r.Name'));

Which is retrieving a parent relationship name field.
The query runs fine but the get() fails: Invalid field. It doesn't recognise 'ns_Distribution_List__r.Name'.
How is the parent relationship name field data retrieved?

 

Thanks

 

Message Edited by nelloC on 03-09-2010 08:40 AM
Best Answer chosen by Admin (Salesforce Developers) 
nelloCnelloC

Anand thanks for your reponse. It's a getSObject() rather than a get, see amended code below

 

Sobject relObj,relObjChild; relObj = Database.query('Select Id, ns__user__c, ns__Distribution_List__r.Name from ns__Distribution_List_User__c where id = \'a0aA0000000aaAAAAA\''); relObjChild = relObj.getSObject('ns__Distribution_List__r'); String listName = String.valueOf(relObjChild.get('Name'));

But is problem solved! Thanks again...

 

Message Edited by nelloC on 03-09-2010 09:29 AM

All Answers

Anand@SAASAnand@SAAS

Try:

 

Sobject relObj,relObjChild;relObj = Database.query('Select Id, ns__user__c, ns__Distribution_List__r.Name from ns__Distribution_List_User__c where id = \'a0aA0000000aaAAAAA\'');relObjChild = relObj.get('ns__Distribution_List__r');String listName = String.valueOf(relObjChild.get('.Name'));

 

 

 

nelloCnelloC

Anand thanks for your reponse. It's a getSObject() rather than a get, see amended code below

 

Sobject relObj,relObjChild; relObj = Database.query('Select Id, ns__user__c, ns__Distribution_List__r.Name from ns__Distribution_List_User__c where id = \'a0aA0000000aaAAAAA\''); relObjChild = relObj.getSObject('ns__Distribution_List__r'); String listName = String.valueOf(relObjChild.get('Name'));

But is problem solved! Thanks again...

 

Message Edited by nelloC on 03-09-2010 09:29 AM
This was selected as the best answer