How to Find Salesforce Object ID Prefix using apex class?

In salesforce every stranded and custom object has specific id.
first 3 digits of an Id is an identifier prefix for object and record (both standard and custom object)

Some Few example:
Account – 001
Contact – 003
Opportunity – 006
User – User

Steps for find Salesforce Object ID prefixes in developer console

First open developer console (Click Your Name and Click Developer Console).
Click Debug and Open Execute Anonymous Window or CTRL+E.
Enter Below code in Anonymous Window and execute.
//change Account with your object API name
system.debug(‘Prifix::’ + Account.sobjecttype.getDescribe().getKeyPrefix());
Change Account name with your object API name (i.e Student__c OR Account)

Find 3 digit object id in Debug log.

Written by 

2x Salesforce MVP | Platform Champion | 18x Salesforce Certified | MuleSoft Certified | 8x Trailhead Ranger | TechForce Services | Sydney | Australia

Leave a Reply

Your email address will not be published. Required fields are marked *