Personal tools
You are here: Home Database Salesforce Planning & Configuration Salesforce IDs and URLs

Salesforce IDs and URLs

Everything has an ID and a name

What ID are you talking about?

Every object in Salesforce (contact, account, opportunity, user, etc) has a 15 or 18 digit ID. You see it in the URL for the record:

https://na5.salesforce.com/0037000000ZhTVW

This ID has 15 digits.  It is case sensitive -- if you use different case you might get a different object, because SF reuses the IDs with different case.

There are also 18 digit versions of every ID.  These are exported by the data loader, for example.  The 18 digit versions are always unique, regardless of case.

This can lead to some confusion, especially if you try to join the 15 and 18 digit versions in an external tool, such as Excel or Access.  They don't match!

Word to the wise: you must avoid joining in Access on ID fields that contain 15 digit IDs!!  I did this once.  Guess what?  Access joins are case insensitive, so I got a lot more records in the query than really exist, because the uppercases joined with their own records AND with the lowercases (for you database geniuses, this is called a cross-product).

Using IDs in Apex

Apex has an ID data type.  It can only hold IDs -- if you try to pass an empty string ('') or any non-valid ID into an ID field, you get an error.

However, Apex will automatically cast strings to IDs (Apex is strongly typed, so this is an exception to the rule).  This means you can assign a string to an ID field and vice versa, and any method that takes an ID will accept a string.

Here's some sample code that illustrates the technique.  My parameter is a string, so that there won't be an error if a non-ID gets passed to the webservice:

WebService static Id doSomething(String contactId) { 

   if (contactId != null && contactId.length() != 15 && contactId.length() != 18) contactId = null;

   // now we know it is either null, or probably a valid ID
}

 

Cool Tricks with URLs

psych!  I don't have time to tell you about these.

 

 

 

Document Actions
« July 2010 »
July
MoTuWeThFrSaSu
1234
567891011
12131415161718
19202122232425
262728293031