1

I have a huge list of 18 digit ids which either refer to a contact or an account. Is it possible to tell which is which without manually checking them all?

2

With just Contacts and Accounts, it's easy: if it starts with 001, it's an Account; with 003 it's a Contact.

More generally, this is called the Key Prefix, this three-digit identifier at the head of the object Id. There are more or less comprehensive references you can find online to map prefixes to objects and vice versa, but the easiest way to go from key prefix to what it is (if it's a regular old sObject) is to just put it in your URL bar:

YOUR_DOMAIN.my.salesforce.com/001

It'll take you to the object home for that object.

  • 1
    Wasn't sure if this worked in LEX or not, so I tried it and whaddaya know, it works! Takes me to the "Recently Viewed" listview in lightning (/o/<obj name>/list?filterName=Recent) rather than the object home (/o/<obj name>/home). – Derek F Jul 15 at 20:43
3

With a single line of Apex, you can identify an ID's object:

System.debug(Id.valueOf('some-record-id').getSObjectType());

This will output a value such as "Account" or "My_Custom_Object__c".

You can run this code by logging in to Salesforce, and choosing Developer Console, then Debug > Execute Anonymous from the menu.

Also, I wrote a package you can use to see ALL key prefixes available in your org (open source!). I'm also working on a Lightning version of this package.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.