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. ':
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'assigned with a constructor
part is where i am confused.I I could execute below code succesuflly,:
Account A1 = new account(name = 'Acc1'); insert A1; Account toUpdate = new account(); toUpdate.id = A1.id;
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
Where am i going wrong?