10 March 2014

A very little key [prefix] will open a very heavy door




Key prefixes hold the proverbial keys to salesforce object kingdom. Key prefixes are the beginning of every unique, immutable id.  Because of their simplicity, its easy to not only identify objects based on their id, it's also possible to interpret the actions that a user performed on that record.

For instance, an id like 001D000000IBVzo/e?retURL=%2F001D000000IBVzo in the browser address bar or a log file indicates someone edited an account record on the na1 instance and was redirected to the detailed view of the record after saving it. There are auto-magical things you can learn from links in general and that magic begins with a key prefix.

There are many uses for key prefixes:
  1. they help in the construction of custom links
  2. they can be used when creating Visualforce pages or Apex code
  3. they are essential to performing data extractions, transformations, and loads using the API
  4. they are used in identifying user activity in the logs
Its with the last use case that I spend a lot of my time. A key prefix allows me to skim across the URI log lines and look for particular objects that a user interacts with so I can better find that needle in the haystack.

The easiest way to find out which key prefix maps to which object is by using a tool like the workbench and the describeSObject() method. After you log into workbench, go to Info > Standard & Custom Objects and pick an object from the pick list.




This method is also the best way to discover a custom object's key prefix since those will be unique to each org, where as standard objects like Account will always be the same across orgs.

You can also obtain a key prefix using Apex. There's a great explanation of this in the Apex help docs with the introduction of the Id.getSObjectType() method.

And finally, when push comes to shove, you can navigate around the app and take a look in the address bar at the resulting ids. Below is a list of some of my favorite ones I obtained either by navigating the app or from other blog sites like Mohammad Usman's sfdchack.blogspot.com or Daniel Ballinger's awesome list on fishofprey.com:


Key Prefix Object Type
'03G' Account Criteria Share
'001' Account
'00r' Account Share
'007' Activity
'04m' Additional Directory Number
'01p' Apex Class
'07L' Apex Debug Log
'707' Apex Job
'01q' Apex Trigger
'099' Apex Component
'07L' Apex Debug Log
'07M' Apex Test Result
'0DS' App Menu Item
'806' Approval
'04i' Approval Request
'ka0' Article
'02i' Asset
'08A' Scheduled Report
'00P' Attachment
'01m' Business Hours
'019' Business process
'00U' Calendar
'04v' Call Center
'701' Campaign
'00v' Campaign Member
'01Y' Campaign Member Status
'08s' Campaign Share
'07O' Canvas
'500' Case
'00a' Case Comment
'01n' Case Share
'010' Case Solution
'01n' Case Share
'02o' Category Data
'02n' Category Node
'5CS' Chat Session
'0F9' Chatter Group
'0FB' Chatter Group Member
'0ca' Chatter Activity
'00a' Comments
'09a' Community
'003' Contact
'02Z' Contact Role
'03s' Contact Share
'069' Content
'800' Contract
'811' Contract Line Item
'00b' Custom Button or Link
'01N' Custom S-Control
'02F' Custom Field Map
'02U' Custom Page
'070' Custom Report Type
'03f' Custom Setup
'02c' Custom Share
'0A7' Custom Share Row Cause
'01r' Custom Tab
'01Z' Dashboard
'0FL' Dashboard Refresh
'02f' Delegated Administration Group
'02h' Delegated Administration Group Assignment
'02g' Delegated Administration Group Member
'00C' Delete Event
'02d' Division
'015' Document
'05X' Document Entity Map
'0I4' My Domain
'091' Email Service
'093' Email Services Address
'018' Email Status
'00X' Email Template
'02s' Email Message
'058' Entity Subscription
'017' Entity History
'00U' Event
'020' Event Attendee
'0AT' Event Log File
'0IM' Export
'0D7' Feed Comment
'0F7' Feed Post
'0D6' Feed Tracked Change
'07F' Feed Favorite
'0I0' Feed Like
'0II' Feed Mention
'09B' Feed Poll Vote
'737' Field History
'1HA' Field History Archive
'0IX' Field Set
'00B' Filter
'022' Fiscal Year Settings
'00l' Folder
'01d' Folder Group
'0AF' Folder Share
'608' Forecast Share
'00A' Forecast Item
'0J9' Forecast Quota
'00G' Group
'011' Group Member
'00G' Group
'02E' Help
'0C0' Holiday
'087' Idea
'00a' Idea Comment
'0Bg' Idea Theme
'0ET' Import
'kA#' Knowledge Article
'00h' Layout
'00Q' Lead
'01o' Lead Share
'016' Letter Head
'0Ya' Login History
'02x' Login Hours
'710' Login IP
'01H' Mail merge Template
'07A' Mass Mail
'063' Mobile Configuration
'086' Mobile Device
'0D5' News Feed
'002' Note
'0JH' Notification
'888' OAuth
'110' Object Permissions
'006' Opportunity
'00J' Opportunity Competitor
'008' Opportunity History
'00k' Opportunity Product
'00t' Opportunity Share
'02r' Opportunity Big Deal Alert
'00K' Opportunity Contact Role
'00k' Opportunity Line Item
'802' Order Item
'801' Orders
'0D2' Org Wide Email Address
'00D' Organization
'04l' Outbound Message
'02l' Outbound Queue
'00l' Partner
'026' Period
'0PS' Permission Set
'0Pa' Permission Set Assignment
'0PL' Permission Set License
'2LA' Permission Set License Assignment
'060' Portal
'061' Portal Account
'067' Portal Member
'01u' Price Book Entry
'01s' Price Book2
'04g' Process Instance
'04h' Process Instance Step
'01t' Product
'00e' Profile
'01k' Field Level Security
'01G' Profile Layout
'01P' Profile Tab
'021' Quantity Forecast
'04X' Quantity Forecast History
'906' Question
'03g' Queue
'0Q0' Quote
'012' Record Type
'00O' Report
'08e' Scheduled Job
'0DM' Site
'04n' Softphone Layout
'501' Solution
'081' Static Resource
'00T' Task
'005' User
'100' User License
'03u' User Preference
'0D5' User Profile Feed
'00E' User Role
'099' Visual force component
'066' Visual force Page
'083' Vote

The most awesome Chris Peterson also pointed out that the instance mapping (the fourth place in the unique id) can be found in the source code for the workbench app.

Key prefixes open many heavy doors. Which ones will it open for you?


12 comments:

  1. I assume the Visualforce development guys are big Gretzky+Lemieux fans?

    ReplyDelete
  2. Worth noting that Daniel Ballinger has a more exhaustive list of key prefixes at http://www.fishofprey.com/2011/09/obscure-salesforce-object-key-prefixes.html.

    And the instance mapping (determined by where the record is CREATED, not where it currently resides) can be found in the source code for the workbench app: https://github.com/ryanbrainard/forceworkbench/blob/master/workbench/config/defaults.php#L220

    ReplyDelete
    Replies
    1. Hi Chris - as always, I'm in awe of your attention to detail. When I went looking for a key prefix blog posting, fish of prey didn't come up. I could have used it as I dug through those log lines. Thanks for sharing it!! There are a couple of key prefixes he doesn't have so I'll try to update his list on his blog.

      Thanks for sharing the instance mapping - great use of code to demonstrate how they map!

      Delete
  3. Thanks Adam for sharing this information and other blog references. It's been very helpful, as I have been trying to play with prefix to display the related mini icon for the object.

    ReplyDelete
    Replies
    1. Thanks Kashi! Let me know how it goes!

      Delete
  4. Hi Adam Torman,
    How to delete objects and fields using visualforce page?

    ReplyDelete
    Replies
    1. Hi k mahesh - not sure your question. Are you looking to determine from the URI if an object was deleted or are you just trying to delete objects via a visual force page?

      Delete
  5. Hi Adam,
    How can i get Field details from '072' prefix Id?.That i have found on Custom ReportType column.Thanks in Advance.

    ReplyDelete
    Replies
    1. Do you mean how do you look up 07 to the custom object or do you mean how do I find details about the custom field?

      Delete
    2. What i meant was, How do you get details about 072 Field Id?.I used Tooling API to query details, it gives no rows.I got this Id from Report_Description column in ReportExport event logfile.

      Delete