Skip to main content
All CollectionsRule documentationRelease readiness
Missed opportunity: Null Coalescing Operator
Missed opportunity: Null Coalescing Operator

Detect null checks that can be simplified with the null coalescing operator.

Gabriele Gallo Stampino avatar
Written by Gabriele Gallo Stampino
Updated over a month ago

Rationale

The null coalescing operator (??) replaces verbose and explicit checks for null references in code.

Before the Null Coalescing Operator:

Integer notNullReturnValue = (anInteger != null) ? anInteger : 100;


With the Null Coalescing Operator, use:

Integer notNullReturnValue = anInteger ?? 100;

Benefits

  • Reduce Apex code base size (up to 10%)

  • Reduce risks of hitting governor limits

  • Save time by auto-fixing these issues with Clayton

Scope

  • Apex

Related resources

Did this answer your question?