0

I am using the following string in a dynamic soql:

   SELECT id, name, orderdate__c, status__c, sold_To_Customer__r.id, sold_To_Customer__r.name, sold_To_Customer__r.customerreference__c, bill_To_Customer__r.id, bill_To_Customer__r.name, bill_To_Customer__r.customerreference__c, Case__r.CaseNumber, Case__r.Reason, Case__r.ContactEmail, Case__r.Description, Campaign__r.Name, Campaign__r.Description FROM Staging_order__c WHERE name = 'SO-1900000020'


 List<sObject> sobjList = Database.query(upper string);

I want to get for example the case description. I tried:

system.debug(sobjList.get(0).case__r.Description);

On saving my class I get the error:

Variable does not exist: case__r

1 Answer 1

2

sobjList is a generic List<sObject>. The sObject class has no property Case__r, and Apex does not resolve properties like this at runtime.

The easiest way to handle this is to declare the result as a List< Staging_order__c>, so that the result of get() is an actual Staging_order__c which has the requisite properties. You could also cast the result of get(), but there doesn't seem to be a reason to store this data in a generic sObject list.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .