Nulls are being rendered in the latest JSON (32.0/33.0). You must explicitly the set the value to null for it to work. Consider the following code:
Account a = new Account(Name='test',Industry=null);
System.debug(LoggingLevel.ERROR, JSON.serialize(a));
Output:
{"attributes":{"type":"Account"},"Name":"test","Industry":null}
If you need every single field, you'll have to do something like:
Account a = new Account();
for(SObjectField f: account.sobjecttype.getdescribe().fields.getmap().values()) {
try { a.put(f, null); } catch(exception e) { }
}
Even better, you could always just use a Map, which avoids the errors of field editability:
Map<String, Object> a = new Map<String, Object>();
SObject b = [SELECT Id, Name FROM Account LIMIT 1];
for(SObjectField f: account.sobjecttype.getdescribe().fields.getmap().values()) {
try { a.put(String.valueOf(f), b.get(f)); }
catch(Exception e) { a.put(String.valueOf(f), null); }
}
System.debug(logginglevel.error, json.serialize(a));
I've just tried this code in executeAnonymous and came up with fully realized JSON. Note that I use a try-catch here because queried SObjects generate errors for missing fields. If you're using a manually constructed SObject, you'll not have to worry about catching errors.
Finally, note that executeAnonymous tends to always run in the latest version. You won't normally see differences in execution contexts because the entire transaction is set to version 32.0 mode when running executeAnonymous. To emulate a lower version, you'd have to write a Visualforce page and set the version of the page to a lower value, and then also set the controller's version to that lower value, etc...
Alternatively, you could write a REST class, and call that REST function. That should also set the version correctly. Since executeAnonymouse is basically an eval(), it tends to behave in the latest version, because it has to be compiled on demand.
One of the techniques I use to debug is create a lightning App and use the component inside the app and only once it is perfectly ready I host it on community .
The problem with community is everytime you change you have to preview and publish and that takes lot of time .
Instead create a lightning App .A sample below
<aura:application>
<c:MorgageComponent/>
</aura:application>
You can open in SFDC with URL /c/MortgageApp.app where MortgageApp is the App name and then you can debug in the browser console .This is really simpler compared to debugging with community skin .
Best Answer
As of Summer '16 you can use the $Resource global in Lightning:
For archived resources:
And use join() for multiple resources:
A timestamp will be automatically added so you don't need to generate your own numbers anymore.