0

I have some code like:

if(s.Primary_Filter_Values__c?.containsIgnoreCase(billingState) || s.Primary_Filter_Values__c?.containsIgnoreCase(billingCountry)) {}

VS Code is throwing me an unexpected token error for the safe navigation syntax. I can save it to the connected org still though. I checked the class API version and this appears to support it according to documentation. Am I missing something here?

<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
    <apiVersion>50.0</apiVersion>
    <status>Active</status>
</ApexClass>
1
  • 1
    have you updated VS Code extension? Seems like this is route cause since you can deploy the changes either way
    – ytiq
    Commented Mar 24, 2021 at 23:29

1 Answer 1

3

Make sure your extensions are up to date. Also, ApexPMD, Prettier, and other plugins may not yet support this operator, so you might get spurious errors. You'll need to check which extension is causing the error and report a bug/issue as apporpriate.

P.S. your code is, ironically, not null safe, despite using the safe nagivation operator. The && and || operators, and if() statements in general, do require a true or false value.

if(s.Primary_Filter_Values__c?.containsIgnoreCase(billingState) == true || 
   s.Primary_Filter_Values__c?.containsIgnoreCase(billingCountry) == true) {}

If you don't include this conditional, you'll get a NullPointerException. I'm working on getting someone's attention on this, as it should be fixed to match the new comparison operator behavior.

1
  • Thank you! And yes, I am apparently a hot mess. I had VS Code in the wrong folder (Mac) so it never updated and I was a year out of date on VS Code and the extension. lol
    – Randy B.
    Commented Mar 24, 2021 at 23:52

You must log in to answer this question.

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