How to get KeyPrefix of sObject in Salesforce

    sfdcsharepoint.com

    Every record in Salesforce has an ID which is used to uniquely identify the record. Each ID value is globally unique. The first three digits represent the object type.

    n

    For example, the Account object uses the 001 prefix; the Note object uses the 002 prefix, Contact uses 003, Users 005, Opportunity 006 etc.

    n

    We can get these prefix values dynamically as well using Apex. To do this, use the below Apex code–

    Schema.DescribeSobjectResult r = Account.getSobjectType().getDescribe();nString keyPrefix = r.getKeyPrefix();

    The key prefixes for all the standard objects remain the same.

    n

    You can use the above Apex code to get the key prefix of your custom objects. To do this just replace Account with the name of your custom object to obtain the key prefix of that custom object.

    Leave a Reply

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