I could see this in Apex developer guide saying:
The ID of an sObject is a read-only value and can never be modified explicitly in Apex unless it is cleared during a clone operation, or is assigned with a constructor.
This assigned with a constructor
part is where i am confused. I could execute below code succesuflly:
Account A1 = new account(name = 'Acc1');
insert A1;
Account toUpdate = new account();
toUpdate.id = A1.id;
4th line does specify Id explicitly and not in constructor?
Where am i going wrong?
insert toUpdate;
... and the error after thatINVALID_FIELD_FOR_INSERT_UPDATE, cannot specify Id in an insert call
.