Posts

Showing posts with the label Null

Salesforce Fact #865 | Null coalescing in JS

Image
We have null coalescing operator in JS as well and it works only with null and undefined. Attached is the screenshot.

Salesforce Fact #861 | Simplified null check in string contains function

Image
Sometimes we may encounter NullPointerException while dealing with the contains() string function. The null check can be simplified using the new Null Coalescing operator. Attached are the screenshots.

Salesforce Fact #818 | Simplified exists check in Map with null coalesecing

Image
Suppose, we want to check if a key does not exist in map or if the corresponding value is null, then it needs to be updated with the new value.  With the new null coalescing operator, the exists check in map can be simplified. Attached is the screenshot.

Salesforce Fact #813 | Null Coalescing Operator in Apex

In Spring'24 release, we have one new operator in Apex i.e. Null coalescing operator. This is an alterative of the null check of any variable. If the left hand side operator is not null return its value else return the value on the right hand side. Previously: String name; String result =  String.isBlank(name) ? 'test' : name; Now: String name; String result = name ?? 'test'; Reference:  https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_NullCoalescingOperator.htm Note: It only works with null value, not with other values like 0 or false. Also, this operator is not supported in bind expression in SOQL queries.