0

I have this data:

Account.Zone__c = 'A';
Zone_set = '{ B, A, C}';

if(!Zone_set.contains(Account.Zone__c)) {
//do this
}

Account.Zone__c = 'B';
Zone_set = '{ B, A, C}';

if(!Zone_set.contains(Account.Zone__c)) {
//do this
}

In first case, condition is true, but on second case, condition is false. How is it possible?

1 Answer 1

1

Sets are one of the few things in Apex that are case-sensitive.

system.debug(new Set<String>{'a'}.contains('A')); would display "false".

It's hard to tell what the issue with your code is, because you've stripped out the details about how your Zone_set is being created. Based on what you've provided though, it seems like the 'B' value may have a whitespace character preceding it.

system.debug(new Set<String>{'B'}.contains('B')); // returns true
system.debug(new Set<String>{' B'}.contains('B')); // returns false
system.debug(new Set<String>{' B'}.contains(' B')); // returns true
1
  • It worked! Thanks!
    – CPS
    Jun 17, 2021 at 12:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .