You need to sign in to do that
Don't have an account?
nelloC
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
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...
All Answers
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'));
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...