Skip to main content
edited title
Link
Swisher Sweet
  • 5.1k
  • 10
  • 66
  • 115

Controller action List.contains returns different results if the user is being debugged

added 251 characters in body
Source Link
Swisher Sweet
  • 5.1k
  • 10
  • 66
  • 115

By no means haveThis last bit of testing I did not enable debugging because I am using a foundnewly created user for running the tests the a solution to this strange problemCommunity profile. I won't be surprised if it randomly stops working againThe user only exists in the context of the test.

But I have seen some strange code behavior innow see that when I ran my dayDeveloper Console snippet, but this one ranksSalesforce automatically created a 30 mins debug session for me. So my original theory is correct, the code responds differently (specifically List.contains) when being run under the context as one ofa debugged user. To prove this, I deleted the strangestDEBUG session for my login, and the tests failed.

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.

This last bit of testing I did not enable debugging because I am using a newly created user for running the tests the a Community profile. The user only exists in the context of the test.

But I now see that when I ran my Developer Console snippet, Salesforce automatically created a 30 mins debug session for me. So my original theory is correct, the code responds differently (specifically List.contains) when being run under the context as a debugged user. To prove this, I deleted the DEBUG session for my login, and the tests failed.

added 1926 characters in body
Source Link
Swisher Sweet
  • 5.1k
  • 10
  • 66
  • 115

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.

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.

Hoping somone will comment that my code logic is sound.
Source Link
Swisher Sweet
  • 5.1k
  • 10
  • 66
  • 115
Loading
Opened case with Salesforce; updated question with result.
Source Link
Swisher Sweet
  • 5.1k
  • 10
  • 66
  • 115
Loading
added 296 characters in body
Source Link
Swisher Sweet
  • 5.1k
  • 10
  • 66
  • 115
Loading
added 177 characters in body
Source Link
Swisher Sweet
  • 5.1k
  • 10
  • 66
  • 115
Loading
Source Link
Swisher Sweet
  • 5.1k
  • 10
  • 66
  • 115
Loading