You need to sign in to do that
Don't have an account?
Anyone have trouble with the containsNone() function?
I'm trying to use the containsNone function to rule out certain values. It seems to not be working as designed.
Looking at the documentation, I'm assuming that the function will make sure that a certain substring is not present in the full string being tested. What I think I'm seeing is that if ANY of the string, including a single letter, is present, the function will consider that string to be 'contained'.
For example, in the following snippet I want to rule out strings that have either MEM, XB or FTB in them.
else if(newOpportunity.Amount > 250 &&
(
newOpportunity.Donation_Code__c.containsNone('MEM') &&
newOpportunity.Donation_Code__c.containsNone('XB') &&
newOpportunity.Donation_Code__c.containsNone('FTB')
) && ...
I did some testing and found that the following strings all got caught in this. (I expected only the second one to.)
B, X, PPXBASSD, F T B (with spaces), F, MME
The strings that didn't get caught are:
CCC, ZZZ, AAA, Y
I was going off of a workflow rule that used - does not contain (MEM, XB, FTB). That worked fine.
Anyone else have similar problems with this?
When trying the here-above code from Developer Console I get:
true, false, false
I expected the 2nd result to return True.
To my humble opinion too , this method is not working well, the best would be to contact SF Support to see what they say.
All Answers
String myString1 = 'abcd';
String myString2 = 'bc';
Integer result =
myString1.indexOf(myString2, 0);
When trying the here-above code from Developer Console I get:
true, false, false
I expected the 2nd result to return True.
To my humble opinion too , this method is not working well, the best would be to contact SF Support to see what they say.
Thanks! Glad to know that something seems to not be working right. Being new to Apex it's usually user error when something is not working as I think it should. :)
For my part, the business has told me that StartsWith will be adequate. I tested that out and it seems to work ok.