viernes, 21 de enero de 2011

http://admios.blogspot.com/2011/01/18-digit-case-safe-id-on-salesforcecom.html

Today while doing a small test to check a Salesforce's API client I noticed that several objects returned by the API, has IDs of 18 characters which I found strange since they are supposed to be 15 letters and numbers, according to the API's documentation.

For reference, an excerpt of the official documentation of salesforce:
ID Field Type

With rare exceptions, all objects in the API have a field of type ID that is named Id and contains a unique identifier for each record in the object. It is analogous to a primary key in relational databases...

ID fields in the Salesforce.com user interface contain 15-character, base-62, case-sensitive strings. Each of the 15 characters can be a numeric digit (0-9), a lowercase letter (a-z), or an uppercase letter (A-Z). Two unique IDs may only be different by a change in case.

With the aim of understanding why the ID returned by the API contain more than 15 characters did a little research and found the following:
Because there are applications like Access which do not recognize that 50130000000014c is a different ID from 50130000000014C, an 18-digit, case-safe version of the ID is returned by all API calls. The 18 character IDs have been formed by adding a suffix to each ID in the Force.com API. 18-character IDs can be safely compared for uniqueness by case-insensitive applications, and can be used in all API calls when creating, editing, or deleting data.

If you need to convert the 18-character ID to a 15-character version, truncate the last three characters. Salesforce.com recommends that you use the 18-character ID.

Conclusion.
So in essence, to prevent problems for those situations when case sensitive differences are not detected the API is returning 18-digits case-safe version of the ID.

Hope this is useful to any of you.
My original post