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)){

        }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;

           update updatedcases;
           } catch (exception e){

2 Answers 2


For the first one, instead of:


use either the Map method containsKey on the Map:


or the Set method contains on the Set:


For the second one instead of trying to access from the List:


access from the Map:


Take a look at the available Trigger Context Variables and also do some Googling about lists and maps to get clear about how to use those most effectively.


The method you're looking for is contains(). containsKey() is in Map, not Set.

  • Aidan, Thanks for that. It solved the error on line 12. Could you help me on line 25. The code : if (trigger.old.get(contactId).phone != trigger.new.get(contactId).phone) Error : Method does not exist or incorrect signature: void get(Id) from the type List<Contact> Jan 29, 2018 at 14:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.