function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
AQAQ 

Object Identifier

As I understand it, every object id always begins with a three character identifier that indicates the type of object.  For example, accounts always begin with 001 and contacts begin with 003.  My custom objects have also been assigned an identifier.

 

Will this three character identifier always be the same regardless of the instance of Salesforce in which it is installed?  In particular, I'm curious if the identifier would be maintained if I packaged my application and then it was downloaded and installed into another Salesforce instance.

 

I'm guessing the answer to this question is no, but I'd appreciate getting confirmation on this if anyone knows a definitive answer.

 

Thanks.

 

SuperfellSuperfell
no, prefixes for custom objects are not stable betweens orgs, even if packaging is used. the describeSobject call (or equivalent in apex) includes the keyprefix so you don't need to hard code this mapping anywhere.
AQAQ

I thought that might be the case.

 

Is there a way to retrieve the prefix in javascript? I'm interested in it to develop context sensitive help.

 

Thanks.

aalbertaalbert

The short answer is No, as you suspected. When you create anew custom object in an org/instance, it creates the key prefix at that time. So if you package up the code with the Id defined and install it in a new org, no guarantees the prefix will be the same. If you create a Sandbox from a Production org, the Ids stay the same. Its a best practice to nothard code those ids.

 

You can use dynamic apex to help determine the object type by Id. Here is a snippet: 

 

http://community.salesforce.com/sforce/board/message?board.id=apex&message.id=12963#M12963

 

 

 

 

SuperfellSuperfell
you can call the describeSObject API via the ajax toolkit from javascript.