PerformNullCheckOnSoqlVariables (Retired)

PerformNullCheckOnSoqlVariables identifies SOQL queries with variables in WHERE clauses that lack null checks. SOQL queries with variables on WHERE clauses become expensive when the variable value is unintentionally null. When the variable value is null, an O(1) operation turns into an O(n) operation. The entire table is scanned but returns no results.

Definition 

Source

@AuraEnabled-annotated methods. @InvocableMethod-annotated methods. @NamespaceAccessible-annotated methods. @RemoteAction-annotated methods. Any method returning a PageReference object. public-scoped methods on Visualforce Controllers. global-scoped methods on any class. Messaging.InboundEmailResult handleInboundEmail() methods on implementations of Messaging.InboundEmailHandler. Any method targeted during invocation.

Sink

Any database operation.

Sanitizer

Null checks (if (x != null) {). Explicit assignment to non-null (String x = 'asdf'). Checks for specific non-null values (if (x == 7) {).

Interpreting Results 

Match any violation message that you receive with this case to understand more about the violation.

Common Case 

Null check is missing for variable targetName used in SOQL query.

The mentioned variable is referenced by a SOQL query, and the variable is missing a null check. This behavior is expensive. Instead, explicitly perform a null check on this variable, or assign it to a specific non-null value. For example:

1public Account[] getAccountsMatchingName(String targetName) {
2	return [SELECT Id, Name FROM Account WHERE Name := targetName;
3}

Retired

As of August 2025, Salesforce Code Analyzer v4 is retired and no longer supported. Use Code Analyzer v5 instead.