function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
HDoshi.ax1738HDoshi.ax1738 

How to write ISNULL in SOQL query

In SQL, we can write  [ SELECT ISNULL(fieldname, 0) AS IsFieldNull FROM tablename ] query.

 

How to write ISNULL in SOQL query like SQL query?

 

Thanks.

 

ForcepowerForcepower
Just compare with null as in

Select id from object where field = null
Rahul_sgRahul_sg
i dont think you can use isNull in SOQL but you can check for Null values in your apex code and then replace null with 0 .
e.g. if(object.fieldName == null)
object.fieldName = 0;
Angie BaiAngie Bai
I have used the following syntax successfully:

select * from CASECOMMENT 
where COMMENTBODY is NULL; 
Claude HebertClaude Hebert
Using IS NULL in a where doesnt replace the ISNULL() function in SQL.

The way SOQL relates object reduces the need for ISNULL but it would still proved additional flexibility in queries.

Setting the default for a possibly null field is very usefull when pulling data to export.