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
GoForceGoGoForceGo 

Using .get with __r

 

This doesn't work. Any ideas?

 

COb__c c = [select Parent__r.Name fro Cobj__c limit 1];


String parentName = c.get('Parent__r.Name');

 

 

jbroquistjbroquist
COb__c c = [select Parent__r.Name fro Cobj__c limit 1];

String parentName = c.get('Parent__r.Name');
String parentName = c.Parent__r.Name; //TRY This?

 Your object names don't match. In the future if you post the error it is very helpful in troubleshooting your problems.

GoForceGoGoForceGo

 

This works.

 

Sobject p = c.getSObject('Parent__r');

p.get('Name');

 

GoForceGoGoForceGo

Thanks. The object names was a typo. Even with that typo fixed, it doesn't work. You have to do what I just posted.

In my case, I do have to use .get, since I don't know the name of the field ahead of time.