Skip to main content
Tweeted twitter.com/#!/StackSalesforce/status/351114153248821248
added 29 characters in body
Source Link
Sergej Utko
  • 22.1k
  • 11
  • 60
  • 88

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?

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?

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?

Source Link
sfdc99999
  • 3.6k
  • 8
  • 44
  • 70

Sobject Constructor and ID

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?