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
Timothy SmithTimothy Smith 

Access Results from SOQL in APEX

Syntax help please.  I am trying to access the fields in my SOQL search.  I am receiving error message:

`System.SObjectException: Invalid field Parent_Project_if_applicable__r.Implementation_status__c for Case`

I verified Relationship name through WorkBench.

My code is:

List<Case> caseList = [SELECT Id, AccountId, Account.Name,Parent_Project_if_applicable__r.Implementation_status__c,
                       FROM Case
                       WHERE AccountId IN :AcctIds];

for(Case cl:caseList){ 
Timothy SmithTimothy Smith
Case object has a lookup relationship to `Parent_Project_if_applicable__c.`
Maharajan CMaharajan C
Hi Smith,

You have to refer like below:

for(Case cl:caseList){
     System.debug(' ==>    '+ cl.getSobject('Parent_Project_if_applicable__r').get('Implementation_status__c'));


Otherwise simply you can refer like below :
System.debug(' ==>    '+ cl.Parent_Project_if_applicable__r.Implementation_status__c');
Danish HodaDanish Hoda
Hi Timothy,
If the fields' names are correct and still you are getting the error, please check the Field-Level Security of those fields for your profile.

Please mark the Best if it solves your issue.