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';
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.
Comments
Post a Comment