Hello friends, In this post we will see  a code example that helps you get the key prefix on any salesforce object. So let's get started

Get salesforce object key prefix in apex

Key Prefix - The salesforce object key prefix is a unique three-character code used to identify and reference specific objects within a salesforce organization. For example : "001" for Account (see below image).



For the code example prospective, I am using account object, you can pick any object as per your requirement.
 String keyprefix = Schema.getGlobalDescribe().get('Account').getDescribe().getKeyPrefix();
 System.debug('Account keyprefix**'+keyprefix);  
Output:
Hope you like this post, for any feedback or suggestions please feel free to comment. I would appreciate your feedback and suggestions.
Thank you.