So I've read a lot about this and it seems that queries run with Database.query(queryString) will skip over any field values set to null instead of returning the property set to null
This has cause a TON of problems in our code and I wondered if anyone knows a workaround.
We are using Dynamic SOQL to output queries as json and did a simple test to see where the values were being stripped out. I originally assumed it was the JSON.serialize() but it appears that it is Database.Query
Here is what we have
public String getJson() {
List<sObject>records = Database.query('Select Name, Site__c from Customer__c Limit 5');
Map<String, Object> result = new Map<String, Object>();
result.put('records', records);
result.put('something', null);
return JSON.serialize(result);
}
Which outputs like this
"records":[{"attributes":{"type":"Customer__c","url":"/services/data/v33.0/sobjects/Customer__c/a0HK000000CxwVjMAJ"},"Name":"fdgdfgd","RecordTypeId":"012K000000053jlIAA","Id":"a0HK000000CxwVjMAJ"},{"attributes":{"type":"Customer__c","url":"/services/data/v33.0/sobjects/Customer__c/a0HK000000CxwVtMAJ"},"Name":"asdf","RecordTypeId":"012K000000053jqIAA","Id":"a0HK000000CxwVtMAJ","Site__c":"a1PK0000001e9AQMAY"}],"something":null}
And you can see the "something" outputs as null just fine but the first customer is missing the Site__c property all together
any suggestions?