I am trying to get the code below to throw and error message if a picklist field (VIP_Type__c) on a custom object already exists in the Parent's (Contact) related list.
I am getting 2 errors and I don't know what they mean or how to resolve. Can anyone help?
Line 19 - Method does not exist or incorrect signature: void contains(String) from the type Set<VIP_Type__c>
Line 27 - Method does not exist or incorrect signature: void add(String) from the type Set<VIP_Type__c>
Set<Id> acctIds = new Set<ID>();
Set<Id> contIds = new Set<ID>();
map<Id, set<VIP_Type__c>> contact_type_map = new map<Id, set<VIP_Type__c>>();
// Get all the Account & Contact Ids in the Set
for(VIP_Type__c vip : Trigger.new){
acctIds.add(vip.Account__c);
contIds.add(vip.Contact__c);
contact_type_map.put(vip.Contact__c, new set<VIP_Type__c>{vip});
}
List<VIP_Type__c> vipRecs = [SELECT Id,Account__c,Contact__c,VIP_Type__c
FROM VIP_Type__c
WHERE Contact__c in:contIds AND ID NOT in:trigger.new];
//Check for VIP Types already entered for Contact
for(VIP_Type__c objVIP: vipRecs){
if(contact_type_map.get(objVIP.Contact__c).contains(objVIP.VIP_Type__c)){
system.debug('@@@### - Error message: '+contact_type_map.get(objVIP.Contact__c));
trigger.newMap.get(objVIP.VIP_Type__c).addError('This Type already exists for this Contact');
}
else{
contact_type_map.get(objVIP.Contact__c).add(objVIP.VIP_Type__c);
}
}