1

In the developer console this works fine:

String op1 = '12345';
String op2 = '1234';
Boolean tmpResult = true;

system.debug('op1: '+op1+', op2: ' +op2+', tmpResult: ' +tmpResult );
tmpResult = op1.contains(op2) ? true : false;
system.debug('op1: '+op1+', op2: ' +op2+', tmpResult: ' +tmpResult );

*USER_DEBUG [14]|DEBUG|op1: 12345, op2: 1234, tmpResult: true*
*USER_DEBUG [16]|DEBUG|op1: 12345, op2: 1234, tmpResult: true*

However, in the Salesforce debug log:

18:15:15.0 (329852706)|USER_DEBUG|[926]|DEBUG|op1: “12345”, op2: “1234”, tmpResult: true
18:15:15.0 (329862345)|STATEMENT_EXECUTE|[927]
18:15:15.0 (329878427)|HEAP_ALLOCATE|[927]|Bytes:5
18:15:15.0 (329886433)|VARIABLE_ASSIGNMENT|[927]|tmpResult|false
18:15:15.0 (329892809)|STATEMENT_EXECUTE|[928]
18:15:15.0 (329901057)|HEAP_ALLOCATE|[928]|Bytes:5
18:15:15.0 (329912132)|HEAP_ALLOCATE|[928]|Bytes:43
18:15:15.0 (329920824)|USER_DEBUG|[928]|DEBUG|op1: “12345”, op2: “1234”, tmpResult: false
18:15:15.0 (329932369)|STATEMENT_EXECUTE|[957]
18:15:15.0 (329934421)|STATEMENT_EXECUTE|[958]
18:15:15.0 (329937300)|HEAP_ALLOCATE|[958]|Bytes:5
18:15:15.0 (329944944)|VARIABLE_ASSIGNMENT|[958]|result|false

After the line 927 tmpResult = op1.contains(op2) ? true : false;, it turns false. The only clue I have is that it returns true if the value is exact same.

I tried tmpResult = op2.contains(op1) ? true : false;, the result is same - only true when it is exact value.

5
  • Have you tried upgrading the API version of the apex class to most recent one?
    – Raul
    Commented Nov 2, 2021 at 22:44
  • @Raul The API version of the Apex class is 47.0, and I can't upgrade it until tomorrow.
    – ApexCowboy
    Commented Nov 2, 2021 at 22:55
  • By the way, tmpResult = op2.contains(op1) ? true : false; is the same as just tmpResult = op2.contains(op1). A Boolean value is already a Boolean value, which is what .contains returns.
    – sfdcfox
    Commented Nov 3, 2021 at 0:16
  • @sfdcfox I think you are right about the double quote, I added op1 = op1.replaceAll('"', ''); op2 = op2.replaceAll('"', '');, but it only works for developer console. In the debug log, system debug still shows the quotes and it still return false
    – ApexCowboy
    Commented Nov 3, 2021 at 4:42
  • @sfdcfox I found out the double quote on my keyboard is different than the one generated in salesforce... copy and pasted that opening and closing double quote works. Cheers
    – ApexCowboy
    Commented Nov 3, 2021 at 5:07

1 Answer 1

2

It appears from your debug statements and the code you have, that the inputs were actually surrounded by quotes: “12345” and “1234”, rather than 12345 and 1234. In this case, neither string will return .contains because of the quotes.

      / Mismatch at 5.
 “12345” 
 “1234”
      \ Mismatch at ”.

Thus, I suspect the problem is not in your code, but in your data. You'll want to check your inputs carefully.

You must log in to answer this question.

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