I found a pretty surprising change in platform behavior today.
Minimum Viable Reproduction (MVR)
Script
It's simple to reproduce. Just run this script in Execute Anonymous
:
Account a = [SELECT Id FROM Account LIMIT 1];
a.Phone = '1111111111';
system.debug(a.Name);
Expected Behavior
There should be an uncaught exception.
Execute Anonymous Error
Line: 3, Column: 1
System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: Account.Name
Observed Behavior
There is no exception, but the field is seen as null.
[3]|DEBUG|null
Question
Is this an intentional change, or a bug that was introduced as part of Spring 17? Or was it introduced in an earlier release and I just didn't notice?
Clarification
I considered it obvious based on the M in Minimum Viable Reproduction, but I should be explicit that I already discovered the behavior is still as expected if you don't set any fields. It seems that setting a field is what causes the change in behavior.
Account a = [SELECT Id FROM Account LIMIT 1];
system.debug(a.Name); // still throws
getPopulatedFieldsAsMap
that track populated fields.