SOQL NULL Filtering: NULL, Empty Values, and Common Mistakes
Null filtering looks trivial, but it becomes important when integrations distinguish missing values from meaningful values.
Find Records with No Value
SELECT Id, Name, Phone
FROM Account
WHERE Phone = null
Find Records with a Value
SELECT Id, Name, Phone
FROM Account
WHERE Phone != null
This is useful before applying logic that assumes the field is populated.
Null in Aggregate Queries
When grouping, null can become its own grouping value:
SELECT Industry, COUNT(Id)
FROM Account
GROUP BY Industry
Accounts without an Industry can therefore affect the aggregate result. If you do not want that group, filter it first:
SELECT Industry, COUNT(Id)
FROM Account
WHERE Industry != null
GROUP BY Industry
Aggregate functions also have function-specific null behavior, so be precise about whether you are counting records or populated field values.
NULL Is a Data-State Question
Do not automatically convert every null into '', 0, or false in downstream code. Those values can mean different things:
null -> value is absent
'' -> text value is empty
0 -> numeric value is explicitly zero
false -> boolean value is explicitly false
That distinction matters in integrations and APIs.
Combine Null Checks with Business Filters
SELECT Id, Name, External_Id__c
FROM Account
WHERE External_Id__c != null
AND LastModifiedDate = LAST_N_DAYS:7
This pattern is often clearer than querying everything and discarding incomplete records later.