what I can understand from your code is you are trying to access contactId from a List type variable. system.debug(campaignlist.contactid); //---- error Variable doesn't exist: You need to iterate through campaignList and then access the contactid like below: for(Campaign cmp :campaignlist){ cmp.contactId; }