Salesforce Object key Prefix List

Object key Prefix

In this article, we are going to explore the Salesforce record ID and Object key Prefix. In Salesforce, we have the advantage of being able to determine the Object type just by looking at the Record ID, whether it is 15 or 18 digits. Every standard object has a distinct prefix (the first three characters of the record). We can make a decision based on that.

Let’s look at one Record ID to understand its format. The ID is 0015g00000NoVcmAAF

Object Key Prefix

Object Key Prefix(KKK):

The key prefix is crucial in identifying the object type. The first three characters of id are key prefixes. Every standard object has a distinct prefix id.

Get the prefix of an Object using Apex: 

Using the apex code below, we can get the prefix value dynamically.

Schema.DescribeSObjectResult r = Account.sObjectType.getDescribe();
String keyPrefix = r.getKeyPrefix();
System.debug('Account key Prefix is ==>' + keyPrefix ); 

19:36:51:003 USER_DEBUG [4]|DEBUG|Sobject key Prefix is ==>001 

getKeyPrefix(): This method returns the object’s three-character prefix code. Record IDs are prefixed with three-character numbers that indicate the type of item (for example, accounts have a prefix of 001 and opportunities have a prefix of 006..)

Similarly, in our apex code, we can identify the object name related to the record id by using the method getsobjecttype().

Id recordId = '0016F00003E2WS0QAN'; 
System.debug('object name>> '+ recordId.getsobjecttype()); 

19:39:13:002 USER_DEBUG [2]|DEBUG|object name>> Account

Some list of frequently used standard object prefix codes in below Table

Prod Identifier(PP):

A salesforce ID’s fourth and fifth characters can be used for identifying the PROD or server the record was created on. It represents the organization’s instance number. The server/data center that hosts our organization is called a salesforce instance. For example, AP24, NA31, and instance of AP24 is “5g”.

Checking the organizational information will allow us to find our instance of the Org

Navigate to Setup -> Company Settings -> Company Information

The salesforce instance is located below Organization Edition in the right column.

Object Key Prefix

Instance code is an abbreviation for the region. My Org instance is ‘AP24,’ which means it is in the Asia Pacific region and is served by data centers in Japan, Kobe, or Yokohama.

Click here to find the Instance status and information. You will get more ideas by entering your instance code.

The third section is RR, which refers to “Reserved for future system use”, The default value is “0”. And NNNNNNNN – Unique alphanumeric identifier, System generates the unique alphanumeric values.

The final part is SSS – An optional three-character suffix to make Ids case-insensitive:
As we all know, Salesforce uses two different record ID formats for different purposes: 15-digit and 18-digit. If we look closely, we can see that the first 15 characters of both IDs are identical, indicating that IDs are case-sensitive. Salesforce uses 15-digit IDs that are case-sensitive; we can find these ID formats in the Salesforce user interface. For example: Reports

When it comes to 18-digit IDs, they are primarily used by the Salesforce API to transfer data between external systems. The majority of other integrations do not require case-sensitive IDs.There are always three capital letters at the end of an 18-character ID. These have been generated using the first 15 characters’ checksum.

For example, As we know 0015g00000NoVcm and 0015g00000NoVCM are not the same. External IDs are not case-sensitive when using external productive tools such as Microsoft Excel, MS Access, and SQL Server; they don’t differentiate between 0015g00000NoVcm and 0015g00000NoVCM. Salesforce.com has come up with an 18-digit character insensitive ID after recognizing this issue. The 15-character ID number is added to create this 18-digit ID, which is case insensitive.

Even Microsoft Excel is unable to identify the above two records as identical, which will cause VLOOKUP operations to return incorrect matching values. Salesforce understood that the 15-digit record ID format had limitations. so they developed an 18-digit record ID format.