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
OutsiderOutsider 

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

I want to update Contact when Status of Campaign Member is changed.  I code below but got error "Initial term of field expression must be a concrete SObject: LIST<CampaignMember> at line 18 column 114" when compile.  May I know why?

 

trigger UpdateContactafterinsertCampaignMember on CampaignMember (after insert) {   
     Map<Id, List<CampaignMember>> CampaignMembersByContactId = new Map<Id, List<CampaignMember>>();
     for (CampaignMember campmem : trigger.new) {
         if(campmem.Contact_Type__c == 'First Contact'){
             if (CampaignMembersByContactId.containsKey(campmem.ContactId)) {   
                 CampaignMembersByContactId.get(campmem.ContactId).add(campmem);
             }//end if
             else {                
                List<CampaignMember> temp = new List<CampaignMember>();            
                temp.add(campmem);            
                CampaignMembersByContactId.put(campmem.ContactId, temp);
             }//end else
         }//end if
     }//end for
     Map<Id, Contact>  ContactsById = new Map<Id, Contact>([SELECT Id FROM Contact WHERE Id in :CampaignMembersByContactId.keySet()]);
     for(Id ContactId : CampaignMembersByContactId.keyset()) {  
         if(CampaignMembersByContactId.stage__c == '1' ) {
              ContactsById.get(contactId).Stage_1_Date__c = CampaignMembersByContactId.get(contactId).Created_Date__c;
              ContactsById.get(contactId).stage_1_Status__c = CampaignMembersByContactId.get(contactId).Status;
           }//end if

JimRaeJimRae

Your issue is with these two lines:

 

ContactsById.get(contactId).Stage_1_Date__c = CampaignMembersByContactId.get(contactId).Created_Date__c;
              ContactsById.get(contactId).stage_1_Status__c = CampaignMembersByContactId.get(contactId).Status;

 

 

Your Map "CampaignMembersByContactID is a map of a ID and a list of CampaignMembers, so your get would return a list of results, not a single result.

You need to identify which CampaignMember from the list you want to get the Stage 1 date and stage 1 status values from.

OutsiderOutsider

May I know how to do that?

 

OutsiderOutsider

solved.