When it comes to navigating to specific records in Salesforce or accurately manipulating data, nothing is more straightforward than using the Salesforce Record ID.
Whether it is the 15- or 18-character one, the first three characters of the ID serve as an identifier for the object type that the record belongs to.
Key Prefix List
Here are some of the commonly used Salesforce objects and their key prefixes:
Object Key Prefixes
Salesforce Object
001
Account
002
Note
003
Contact
005
User
006
Opportunity
500
Case
701
Campaign
007
Activity
00B
ListView
00D
Organization
00E
UserRole
00G
Group
00I
Partner
00O
Report
00P
Attachment
00Q
Lead
00T
Task
00U
Event
00X
EmailTemplate
00e
Profile
00h
Layout – Page Layout
01s
Pricebook2
01u
PricebookEntry
01t
Product2
00k
OpportunityLineItem
00l
Folder
00v
CampaignMember
01Z
Dashboard
01a
DashboardComponent
02c
Sharing Rule
01p
ApexClass
01q
ApexTrigger
03u
UserPreference
800
Contract
801
Order
802
OrderItem
806
Approval
Retrieve the List of Key Prefixes From Your Org
Considering that no Salesforce org has the exact same objects, and you may be looking for the key prefix of a custom object and rather than a standard one from the list above, the EntityDefinition has got you covered! This object provides data about both custom and standard objects, including the KeyPrefix information. With a simple SOQL query, you can retrieve the information you need directly from your org:
SELECT Label, KeyPrefix FROM EntityDefinition
Depending on how many objects you have in your org, the query above might result in the following error:
EXCEEDED_ID_LIMIT: EntityDefinition does not support queryMore(), use LIMIT to restrict the results to a single batch.
If you are facing this error, you can either use the LIMIT clause, as the error message suggests, to only retrieve a maximum of two thousand results, or alternatively, leverage the WHERE clause to filter by Label or DeveloperName, for example, if you need the prefix of a specific object.
SELECT Label, KeyPrefix FROM EntityDefinition LIMIT 100
SELECT DeveloperName, KeyPrefix FROM EntityDefinition WHERE Label = 'Your Object'
When to Use Salesforce Object Key Prefixes
Formulas, Validation Rules, or Automations
Object prefixes are very useful when it comes to user and queue criteria for objects such as cases or leads. You could create a formula field for this use case, depending on the situation and preference.
Since the user and queue (group) are two different objects, it becomes really easy to have a Salesforce Flow execute – for example, only when a lead is owned by a user and other criteria are met.
Additionally, if you are using Tasks and Events in your org, you might consider leveraging the object key prefix in relation to the WhatID. For example, if there is an automation to be triggered every time a task is completed and is related to an opportunity, but a different automation when the task is related to a custom object record, you can use the KeyPrefix in a Decision element within a Salesforce Flow to easily determine the path that will be taken based on the record.
Summary
Finally, prefixes are an easy way to identify most Salesforce objects. As you continue to work with Record IDs, chances are that at some point, you will know most of them by heart. You also have the option to use a query and find out this information about an object in a few seconds, and further use it even in automations.
Have you used the Object Key Prefixes for any use case or process? Let us know in the comments below!
The Author
Andreea Doroftei
Andreea is a Salesforce Technical Instructor at Salesforce Ben. She is an 18x certified Salesforce Professional with a passion for User Experience and Automation.