As pointed out in other questions some fields are queried in APEX even if not mentioned explicitly, including Id field.
I can remember these fields could be used only for reading data, not for actually updating records, meaning you had to explicitly query Id field to update a record, but you could read Id value without querying it.
So code like this would throw an error:
Account acc = [SELECT Name FROM Account Limit 1]; acc.Name="Test"; update acc; // Error - SObject row was retrieved via SOQL without... or something like that
But code like this would not throw an error:
Account acc = [SELECT Name FROM Account Limit 1]; System.debug(acc.Id);
But it is no longer the case. Or it never was?
Help me with this I’m losing mind over this!
Read more here: Source link