Skip to main content

Null Pointer Exception

Explore practical guides and implementation patterns for this topic.

Posts

Topic Apex
Apex Development

How to Use the Safe Navigation Operator (?.) in Salesforce Apex

In plain words: The Safe Navigation Operator ( ?. ) in Salesforce Apex evaluates the left-hand side of an expression. If that value is null , it immediately returns null instead of throwing a dreaded System.NullPointerException (NPE). Null pointer exceptions are among the most common run-time errors in Apex development. Traditionally, guarding against them required writing layers of verbose if (variable != null) checks. The safe navigation operator streamlines your code by letting you chain references and method calls safely on a single line.
Read article