Posts

Showing posts from November, 2020

Safe Navigation Operator in Apex

Hello Ohana, It's been quite some time after my last blog as i was caught up with some personal and professional engagements, But nevertheless here i am back with one of the coolest apex features that i found with Winter 21 release. I was waiting the release to go live before i post this blog and now since WI 21 is live so lets discuss how to use it.  Before we begin with code example lets understand what exactly is safe navigation operator (?).  In very simple words it reduces the need to check for Null before accessing variable or method values which could cause Null Pointer Exception if left without checking. So now to answer the very obvious next question that "Can we get rid of all error handling and use Safe navigation Operator ?  instead" Answer is "No", what safe navigation does is instead of halting the code execution and throwing null pointer exception it simply returns null. Now lets understand it with an example.  Old Code to return null after checki