I'm working on a function that does a series of
.getSObject() calls from an Account record to get three fields from one of the related records.
The issue I'm having is one of the fields returns a
SObject row was retrieved via SOQL without querying the requested field error when doing the .get(), but the other two work fine.
This is what each call looks like, with a different field retrieved each time (account is an Account record that gets passed in):
SObject r = account.getSObject('Related1__r'); String test = (String) r.getSObject('Related2__r').get('fieldName__c');
It's not clear from Salesforce documentation what the object returned from
.getSObject() and why it works fine for two fields but fails for the third. I can do a dynamic SOQL query to retrieve the same record that should be returned from the
.getSObject() call and then do a
.get() on the exact same field but when I try to do the code snippet above for that particular field, it fails. It seems as if the
.getSObject() only retrieves a subset of the fields, and in my case it doesn't include the field I need.