2
votes

This is an APEX code related question and is specific to a VisualForce controller class.

Question
I am trying to update a record with a known AccountId. However, when I set the ID in the sObject declaration SalesForce is appending the string "IAR" to the end of the ID!

Can someone please let me know what I am doing that is wrong and if I am going about this in the wrong way than what is the correct way to update a record from a custom method, outside of quicksave() or update().

Description
So basically, the user will come to this page with the id encoded and it will either have an id or a level. This is handled by the function decode() which takes a string; "id" / "level". I then create an Account variable "acc" which will be used to store all of the Account information before we insert or update it with the statement "insert acc;". Since, I cannot set the ID for "acc" with "acc.id = salesForceID" I have decided to set it when "acc" is created. The following APEX code occurs in the constructor when it is declaring the "acc" variable.

URL Variable Passed
/application?id=001Q000000OognA

APEX Controller Class (Abridged)

salesForceID = decode('id');
debug1       = 'salesForceID: ' + salesForceID;

acc          = new Account(id = salesForceID);
debug2       = 'Account ID: ' + acc.id;

Debug Output
salesForceID: 001Q000000OognA
Account ID: 001Q000000OognAIAR

Comments
I apologise for the brevity of the code given, this is for security reasons. I am basically trying to set the ID of the acc before I insert/upsert/update it. I appreciate any explanations for why it could be appending "IAR" and or any alternate ways to update a record given an input AccountId. I do understand that if you pass the id in as a URL variable that SalesForce will automatically do this for you. However, I am passing more than one variable to the page as there are three separate use cases.

Thanks for your help.

1

1 Answers

4
votes

001Q000000OognA is the "standard" 15-character Salesforce ID. 15-character ID's are case-sensitive.

001Q000000OognAIAR is the case-insensitive 18-character version of that ID.

Either one is fine. You do not need to worry about the difference. If for some reason you really need to use the 15-character version in parameters etc, you can safely truncate the last 3 digits.

More information here: http://www.salesforce.com/us/developer/docs/api/Content/field_types.htm