[SalesForce] Error “Initial term of field expression must be a concrete SObject: LIST” when fetching values from list

Can someone please help me here?I have the piece of code here alongwith the error I am facing.
Apex class:Code snippet:

Map<Id,Attachment> mapCaseAttachments = new Map<Id,attachment>();
for (List<Call2_vod__c> c : listOfLists) {
    attachment atf = mapCaseAttachments.get(c.Account_vod__C);
    attachmentCaseWrapper cw = new attachmentCaseWrapper(c,atf);
    caseWrapper.add(cw);
}

Error:

Compile Error: Initial term of field expression must be a concrete
SObject: LIST

Best Answer

You're cycling through a list of lists, not a list of SObjects.

for (List <Call_to_Vod__C> c : listOfLists) {    
  attachment atf = mapCaseAttachments.get(c.Account_vod__C);    
}

The error message is pretty clear actually:

Initial term of field expression must be a concrete SObject: LIST

  • You have a field expression c.Account_vod__C
  • The initial term of that expression is c
  • c is not an SObject, it is a LIST

If you want to get at the SObject:

for (List <Call_to_Vod__C>  cs : listOfLists) {   
  for (Call_to_Vod__C c : cs)    {
     /// bla bla c.Account_vod__C   
  } 
}
Related Topic