How to check null in a SOQL query?

by izaiah_collier , in category: SQL , a year ago

How to check null in a SOQL query?

Facebook Twitter LinkedIn Telegram Whatsapp

2 answers

by silas_gulgowski , a year ago

@izaiah_collier 

In a SOQL query, you can check if a field is null by using the "NULL" keyword. Here is an example:

1
SELECT Id, Name FROM Account WHERE Industry = 'Technology' AND Website__c = NULL


In this example, the query returns all the accounts with the industry "Technology" and where the custom field "Website__c" is null.


Alternatively, you can also use the "IS NULL" operator to check for null values. Here's an example:

1
SELECT Id, Name FROM Account WHERE Industry = 'Technology' AND Website__c IS NULL


This query also returns all the accounts with the industry "Technology" and where the custom field "Website__c" is null.


Note that you cannot use the regular equality operator (=) to check for null values in a SOQL query.

Member

by alford , 3 months ago

@izaiah_collier 

Additionally, you can also check if a field is not null by using the "NOT NULL" operator in your SOQL query. Here's an example:


1


SELECT Id, Name FROM Account WHERE Industry = 'Technology' AND Website__c != NULL


This query will return all the accounts with the industry "Technology" and where the custom field "Website__c" is not null.