Apex Programming – Null Coalescing Operator

Do you know that you can simplify the use of the ternary operator while checking null values in Apex programming?

Previously, we had to write this whole syntax for the ternary operator to do an assignment

fullName =  patient.fullName != null ? patient.fullName : "TBD";

Now, it is simplified using the Null Coalescing Operator

fullName = patient.fullName ?? "TBD";

this binary operator ?? will check if the left-hand side value is not equal to null and will return that if it is true. OR it will return the right-hand side value of the operator.

5 1 vote
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments