It's been weeks since posting this problem, and Salesforce can't help and I took another look at it today. I painstakingly debugged a user using System.assert
in unit tests I wrote for it and what I saw was astounding.
I found that Salesforce would inconsistently return false
on List.contains()
when I proved that the List contained the items I was looking for. Here are actual debug printouts from Salesforce when it was running false:
selectedSkills[0].Skill__c: a0c1F000000IZ0rQAG
skills[0].Id: a0c1F000000IZ0rQAG
skills1.Id: a0c1F000000IZ0sQAG
selectedSkillIds[0]: a0c1F000000IZ0rQAG
selectedSkillIds.contains('a0c1F000000IZ0rQAG'): false
selectedSkillIds.contains('a0c1F000000IZ0sQAG'): false
I bolded the matching strings. Even though selectedSkillIds
contained a0c1F000000IZ0rQAG
it still returned false.
This is where it gets weird. I recreated a simple contains test in Developer Console, and the contains
method worked correctly.
I reran my test again and amazingly, the contains
method worked correctly in the test. I made no changes to the code/login and I got different results. The only thing I did was run a code snippet in Developer Console to very List.contains
was working as I expect.
Here's the output again with it working (again, bolded where matched):
selectedSkills[0].Skill__c: a0c1F000000IZ1GQAW
skills[0].Id: a0c1F000000IZ1GQAW
skills1.Id: a0c1F000000IZ1HQAW
selectedSkillIds[0]: a0c1F000000IZ1GQAW
selectedSkillIds.contains('a0c1F000000IZ1GQAW'): true
selectedSkillIds.contains('a0c1F000000IZ1HQAW'): false
By no means have a found a solution to this strange problem. I won't be surprised if it randomly stops working again. I have seen some strange code behavior in my day, but this one ranks as one of the strangest.