I'd like to get straight exactly what is happening when I create an sObject in Force.com code but can't find any information on the specifics.
The Id is null until after the DML insert statement. Does this mean that the Id is being assigned as a result of a return value from the database?
This leads me to wonder if I could get more than one value back from the insert.
Is it possible to insert and then select back all of the automatically created fields such as Case.CaseNumber in one statement? Or is the sequence below (a DML insert followed by a SOQL SELECT to get specific fields) the only / correct way to do this?
Case c = new Case();
System.assert(c.Id == null); // id not created on Case construction
System.assert(c.CaseNumber == null);
insert c;
System.assert(c.Id != null); // not null after insert
System.assert(c.CaseNumber == null); // still null after insert
c = [SELECT Id, CaseNumber FROM Case WHERE Id = :c.Id];
System.assert(c.Id != null);
System.assert(c.CaseNumber != null); // not null after select from database