Questions tagged [safe-navigation-operator]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
4 votes
0 answers
66 views

Unexpected NullPointerException with Safe Navigation operator

We are seeing an intermittent failure from an integration that creates Tasks; it is throwing a NullPointerException in our Task Trigger handler. TaskTrigger: execution of AfterUpdate caused by: ...
Jason Clark's user avatar
  • 11.6k
-2 votes
1 answer
210 views

Apex : Safe Navigation not working

I am replacing ternary ? with safe navigation but not working :(, what's wrong String a,b ='foo'; a = a?.b; // why not working, i want this Ex : a = a == null ? b : a; System.debug('a::'+a); // foo
Sarvesh's user avatar
  • 988
3 votes
1 answer
689 views

Null pointer exception using null safe navigation operator

Following scenario throws nullptr exception inside if condition block !sample?.SomeField__c: MyObject__c sample = null; if (!sample?.SomeField__c) { ... } Why is that? Shouldn't that be evaluated ...
Rechu's user avatar
  • 452
4 votes
1 answer
366 views

Minified code in LWC is wrong because of optional chaining operator

I have a LWC that has a simple getter function that controls whether to display an element or not: get _isGridNotEmpty(){ return this._gridData?.length > 0; } However I found that the element ...
unhinged's user avatar
  • 354
0 votes
1 answer
191 views

Unexpected Token for Safe Navigation Syntax

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 ...
Randy B.'s user avatar
  • 139
17 votes
1 answer
1k views

Safe Navigation Operator (?.) and integer comparisons

While reviewing a teammate's code, I was surprised to find the following pattern, which works: static void myFunction(List<String> stringArray) { if (stringArray?.size() > 0) { ...
Matthew Souther's user avatar