I am getting the following error on line 12 and 25 and would need some help in resolving it.
Error on line 12:
Method does not exist or incorrect signature: void containsKey(Id) from the type Set
Error on Line 25:
Method does not exist or incorrect signature: void get(Id) from the type List
trigger UpdateContactPhoneNumberOnCases on Contact (after update) {
List <case> affectedCases = [select id, Contact_Phone__c from case
where contactId in : trigger.newMap.keyset()];
// A map of contact Ids -> to list of cases
map<id, list<case>> affectedCasesByContactId = new Map<Id,List<case>>();
// Now populate the map (affectedCasesByContactId)
for (case c: affectedCases) {
**12---->** if (affectedCasesByContactId.keyset().containsKey(c.contactId)){
affectedCasesByContactId.get(c.contactId).add(c);
}else {
affectedCasesByContactId.put(c.contactId, new List<case>{c});
}
}
// create a new list to hold our newly updated cases
List <case> updatedcases = new List<case>();
for (Id contactId: trigger.newMap.keyset()) {
**25--->** if(trigger.old.get(contactId).phone != trigger.new.get(contactId).phone)
{
for (case thisCase: affectedCasesByContactId.get(contactId)){
thisCase.Contact_Phone__c = trigger.new.get(contactId).phone;
updatedcases.add(thisCase);
}
}
}
try{
update updatedcases;
} catch (exception e){
system.debug(e.getMessage());
}
}