Bug in List.contains for Id data type?

Am not doing anything fancy, just trying to use contains method of list.

List<Id> myIdList = new List<Id>();

Id oppId ='0060E000008PdMk';   

System.debug(myIdList.contains(oppId)); //Returns false

To my surprise, I spent a few hours debugging and came with this problematic code. Are we not supposed to use contains for List<Id> ?

Changing the type from List<Id> to List<String> makes my code run, but I dont have any clue why it does?

Can anyone shed some light?

UPDATE : As per the suggestion of sfdcfox I have raised a case with SF support. Case number “19522568”. I will keep you guys updated with the results.

UPDATE 2 : Salesforce reached out to me for this,

A bug W-4884673 already exist for this issue. SF R&D team is working on the same. Known issue link for reference: https://success.salesforce.com/issues_view?Id=a1p3A000000AT9c

There isn’t any ETA for this to be fixed, so the case will be closed as “bug fix submitted”

UPDATE 3 : This has now been resolved


Looks like this bug System.hashCode broken on Id properties of SObjects? remains unfixed.

Diagnosis is made more confusing because of this hashCode() is never called when adding to Maps and Sets where the debug level determines if hashCode is called or not.

Source : Link , Question Author : Pranay Jaiswal , Answer Author : Keith C

Leave a Comment