You need to sign in to do that
Don't have an account?
Accessing Relationship fields dynamically
Hi,
I am usng dynamic soql, where I prepare my sqol query at runtime and would like to access the field values using dynamic field names used in my query. I am able to do it using sObject method get(stringName) but this works only for non-relationship fields and not relationsip fields. Please let me know if I am missing anything and how to access relationship field using get() method.
Below is the simple code snippet
String qryString = "SELECT Id, AccountId, Account.AccountNumber from Order limit 2" (note the field names will be computed at runtime, I am just hard coding here)
Order[] ords=Database.query(qryString);
for(Order ord : ords){
System.debug('Account ID...'+ord.get('AccountId'));//This works and prints the accountID
System.debug('Account number..'+ord.get( 'Account.AccountNumber'); //get an error "Account.AccountNumber does not belong to SObject type Order
}
Thanks.