Skip to main content

Clayton Missed opportunity: Null Coalescing Operator

David Martin avatar
Written by David Martin
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?