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
Vivek KidambiVivek Kidambi 

database.query does not return fields with null value. is there a way I get even fields with null values?

KaranrajKaranraj
The Database.query will return the record based on the query string. Check whether you have any where condition in query to filter null values?
 
CLKCLK
In queryResult, there wont be any value. But anyway, when you are parsing SObject to specific type, then the fields which haven't returned the value will be displayed as null.

e.g. Contact clk = new Contact(lastName = 'k');
       insert clk;



List<sObject> sobjList = database.query('select firstName from Contact where lastname = '\k'\');
Contact c = (Contact) sobjList[0];
system.debug(c.FirstName);


Result would be - null
CLKCLK
or if you do  
sobjList[0].get('FirstName')
it would return null as well.