You need to sign in to do that
Don't have an account?
Kiranpreet Kaur
SOQL query exclude null values in apex class
| Id |Name |Language|
|xxxxxxx | abc | |
When I query the above record and debug this record in apex class it shows:- (Library__c:{Id=xxxxxxxxxxxx, Name=abc})
It is not showing language.
The query is :- Select id,name,language__C from Library__c
Actually, I need to create JSON from the query result. As the query result not showing the null or empty values, therefore, Json is also not including the null and empty values.
|xxxxxxx | abc | |
When I query the above record and debug this record in apex class it shows:- (Library__c:{Id=xxxxxxxxxxxx, Name=abc})
It is not showing language.
The query is :- Select id,name,language__C from Library__c
Actually, I need to create JSON from the query result. As the query result not showing the null or empty values, therefore, Json is also not including the null and empty values.
As far as I know, System.debug does not print fields with null value but I will be glad to be wrong about this.I am not able to find any documentation to support this but I tried this in my org and the debug doesn't print null field.
or
Prepare a wrapper for Your JSON object and then assign the values from objects from query to wrappers, then You will always have values or null.
Hope this helps.
Thanks,
Nagendra.