Skip to main content
added 281 characters in body
Source Link
Simon Lawrence
  • 6.8k
  • 5
  • 35
  • 57

Setting the ID in the account in your method will pass, and "run" but you will encounter an error should you then try to insert that account via DML as per below:

enter image description here

So whilst having the ID in your Account in memory might prove useful in some scenarios, you are not really setting the Salesforce ID (once the object gets to the Salesforce data layer).

Incidentally this line:

Account a = new Account(id='0019000000sAr8H');

IS the "constructor" for an Account object, and so it is perfectly valid as-per the documentation to set the Id here. Where this line then appears in your code is of no consequence to this rule.

Edit: from Keith's answer, I've always wondered what use this would have, and updating records without having to query sounds pretty plausible..!

Setting the ID in the account in your method will pass, and "run" but you will encounter an error should you then try to insert that account via DML as per below:

enter image description here

So whilst having the ID in your Account in memory might prove useful in some scenarios, you are not really setting the Salesforce ID (once the object gets to the Salesforce data layer).

Edit: from Keith's answer, I've always wondered what use this would have, and updating records without having to query sounds pretty plausible..!

Setting the ID in the account in your method will pass, and "run" but you will encounter an error should you then try to insert that account via DML as per below:

enter image description here

So whilst having the ID in your Account in memory might prove useful in some scenarios, you are not really setting the Salesforce ID (once the object gets to the Salesforce data layer).

Incidentally this line:

Account a = new Account(id='0019000000sAr8H');

IS the "constructor" for an Account object, and so it is perfectly valid as-per the documentation to set the Id here. Where this line then appears in your code is of no consequence to this rule.

Edit: from Keith's answer, I've always wondered what use this would have, and updating records without having to query sounds pretty plausible..!

Source Link
Simon Lawrence
  • 6.8k
  • 5
  • 35
  • 57

Setting the ID in the account in your method will pass, and "run" but you will encounter an error should you then try to insert that account via DML as per below:

enter image description here

So whilst having the ID in your Account in memory might prove useful in some scenarios, you are not really setting the Salesforce ID (once the object gets to the Salesforce data layer).

Edit: from Keith's answer, I've always wondered what use this would have, and updating records without having to query sounds pretty plausible..!