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
BKWBKW 

Error: Intial Term of field expression must be concrete SObject:List.

I am working on some code in Dev Console (part of a larger trigger). Basically I am trying to pull the OwnerID of a record on a custom object. Then run a new list to pull the name of the owner from the user records based on the result from the initial query. 

The last row is giving me the Intial Term of field expression must be concrete SObject:List. error. The Field OwnerID is pulled with the list.  Any thoughts as to why I am getting this error?  If I comment out the last line it executes fine including pulling the ownerID.

 

 
String  ClientID;
 
 List<Client__c> Cl = new List<Client__c>();
List<User> U = new List<User>();
     
ClientID = '112465';
Cl = [Select ID, Name, OwnerID from Client__c Where Name = :CLientID];
U = [Select ID, Name from User Where ID = :Cl.OwnerID];

SLockardSLockard

That is because your variable Cl is a list, so you cannot check all of the OwnerID's by doing Cl.OwnerID. Instead I would try:

 

String  ClientID;
 
List<Client__c> Cl = new List<Client__c>();
List<User> U = new List<User>();
List<ID> ClientOwnerIDs = new List<ID>();
     
ClientID = '112465';
Cl = [Select ID, Name, OwnerID from Client__c Where Name = :CLientID];

for (Client__c client : Cl)
{
   ClientOwnerIDs.add(client.OwnerID);
}

U = [Select ID, Name from User Where ID IN :ClientOwnerIDs];

 

BKWBKW

SLockard,

That did make that code segment work Thanks. But that still leaves the result in a list, and I having the same problem when I try to populate a variable with the Client owners name.  I may be going at this all wrong. But here is what I am trying to do.

 

Pull a list of clients (really only one Client) based on the Client Number listed on the case.

Grab the owner ID from the Client Record.

User the owner ID on the client record to pull the Owner Name from the User Object. 

Populate the Owner Name in a case variable.

 

From what you have below, how would I now get that Owner Name to become a variable for use in my trigger?

 

SLockardSLockard
String  ClientID;
 
List<Client__c> Cl = new List<Client__c>();
List<User> U = new List<User>();
List<ID> ClientOwnerIDs = new List<ID>();
     
ClientID = '112465';
Cl = [Select ID, Name, OwnerID from Client__c Where Name = :CLientID];

for (Client__c client : Cl)
{
   ClientOwnerIDs.add(client.OwnerID);
}

U = [Select ID, Name from User Where ID IN :ClientOwnerIDs];

for (User usr : U) // for each User in the list U, call that current User usr
{
// logic here
// access user's name (aka the owners name) by :
system.debug(usr.Name);
}