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
TerminusbotTerminusbot 

Apex List: SOQL query Question

I am trying to get a string value off the User object. When I run a debug it is returning not only the Sagitta_User_Code__C, but the ID as well. I just want to get the Sagitta_User_Code__c. How do I isolate just the value of the Sagitta_User_Code__c. 
 
List<User> accountOwner = [Select Sagitta_User_Code__c From User where id =: accnt.ownerid];
        System.debug('Sagitta Login: ' + '' + accountOwner);

Debug Log:
 
|USER_DEBUG|[22]|DEBUG|Sagitta Login: User:{Sagitta_User_Code__c=ral, Id=005400000032HgHAAU}

 
Best Answer chosen by Terminusbot
mritzimritzi
if you want to use the value of Sagitta_User_Code__c field then use can use following method.
 
for(User u:accountOwner){
    System.debug(u.Sagitta_User_Code__c);
}

for directly accessing field valu of a particular record in accountOwner List
use:
accountOwner[5].Sagitta_User_Code__c;

Mark this as Best Answer, if this helps solve your problem.

All Answers

mritzimritzi
if you want to use the value of Sagitta_User_Code__c field then use can use following method.
 
for(User u:accountOwner){
    System.debug(u.Sagitta_User_Code__c);
}

for directly accessing field valu of a particular record in accountOwner List
use:
accountOwner[5].Sagitta_User_Code__c;

Mark this as Best Answer, if this helps solve your problem.
This was selected as the best answer
TerminusbotTerminusbot
This worked. 
 
accountOwner[0].Sagitta_User_Code__c;

Not sure what the [5] was referencing. 

Thanks,
Ricky 
mritzimritzi
That's an example.

[5] represents the index. It gives value of 6th record in the list accountOwner, if the list has 6 or more records.
The index can range from 0 to N-1, where N is the size of list acccountOwner.