Skip to main content

Questions tagged [safe-navigation-operator]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
1 vote
1 answer

LWC Addition Assignment Operator (+=) appending

I have a lWC that is summarizing a total. If I have a single row the Cost summary works but when a new row is added it fails because it adds a 0 to the front of the total and I am not sure why. Its ...
Phuc's user avatar
  • 373
4 votes
0 answers

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.9k
-2 votes
1 answer

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
  • 998
3 votes
1 answer

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

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

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

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