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
LavielLaviel 

How to retrieve selected picklist item from apex trigger

I'm trying to retrieve the selected picklist item from the Case object, field Status. My objective is to use this value for a condition and eventually set a new one based on a different logic. But my main issue is every time I try to query the selected item for the Case object I encounter this issue:

 

"System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: Case.Status"

 

You may see my sample code below: This is just part of my debugging to atleast display the selected value on the error message, but I could not even get the selected item

 

for (Case c:cases){
            Case parentCase;
            String parentId = c.ParentId;
            String siblings = ' :: ';
            String selectedStat;
            String display='';
            
            List<Case> siblingCases = new List<Case>{};
            parentCase = [select Subject, Id from Case where Case.Id = :parentId];
           
            display = parentCase.Status;
            c.addError(display);

}

Best Answer chosen by Admin (Salesforce Developers) 
Ronak PatelRonak Patel

Your Logic is right but missing only one field in SOQL

Change your Query to

 

            parentCase = [select Subject, Id,Status from Case where Case.Id = :parentId];

 

Problem solved...

All Answers

Ronak PatelRonak Patel

Your Logic is right but missing only one field in SOQL

Change your Query to

 

            parentCase = [select Subject, Id,Status from Case where Case.Id = :parentId];

 

Problem solved...

This was selected as the best answer
LavielLaviel

Hi Ronak,

 

Thanks did not notice that missing Field from sa SOQL.

Thanks for pointing it out. :smileyhappy: