+ Start a Discussion
B kldB kld 

Case Object record Id Should always start with "500........"?

Case Object record Id Should always start with "500........" in any SandBox or Production or Developer Edition
or anywhere in Salesfore whatever the region may be..?

What about remaining objects like Account , Opportunity..etc...

 
Himanshu ParasharHimanshu Parashar
Hi,

That is correct, every standard object prefix is identical regardless of Salesforce edition here is quick list

Account : 001
Contact :  003
Opportunity : 006
Solution : 501
Lead : 00Q
Campaign : 701

Thanks,
Himanshu
Amit Chaudhary 8Amit Chaudhary 8
Hi B kld,

Yes you are Right, Below are the prefix for all other object.

Entity                                                        Prefix
 
    ACCOUNT                         '001'
    QUOTE                           '0Q0'
    NOTE                            '002'
    CONTACT                         '003'
    USERS                           '005'
    OPPORTUNITY                     '006'
    ACTIVITY                        '007'
    OPPORTUNITY_HISTORY             '008'
    FORECAST_ITEM                   '00A'
    FILTER                          '00B'
    DELETE_EVENT                    '00C'
    ORGANIZATION                    '00D'
    USER_ROLE                       '00E'
    QUEUE                           '00G'
    GROUPS                          '00G'
    PARTNER                         '00I'
    OPPORTUNITY_COMPETITOR          '00J'
    OPPORTUNITY_CONTACT_ROLE        '00K'
    CUSTOM_FIELD_DEFINITION         '00N'
    REPORT                          '00O'
    ATTACHMENT                      '00P'
    LEAD                            '00Q'

Please check below post to check other object prefix also
https://help.salesforce.com/apex/HTViewSolution?urlname=Standard-Field-Record-ID-Prefix-Decoder&language=en_US (https://help.salesforce.com/apex/HTViewSolution?urlname=Standard-Field-Record-ID-Prefix-Decoder&language=en_US)

You can get prefix of any custom object by below code:-
Schema.DescribeSObjectResult r = CustomObject__c.sObjectType.getDescribe();
String keyPrefix = r.getKeyPrefix();
System.debug('Printing --'+keyPrefix );

you can try below code to get prefix:-
public class SchemaGlobalDescribe{
    public static String findObjectNameFromRecordIdPrefix(String recordIdOrPrefix){
        String objectName = '';
        try{
            //Get prefix from record ID
            //This assumes that you have passed at least 3 characters
            String myIdPrefix = String.valueOf(recordIdOrPrefix).substring(0,3);
             
            //Get schema information
            Map<String, Schema.SObjectType> gd =  Schema.getGlobalDescribe(); 
             
            //Loop through all the sObject types returned by Schema
            for(Schema.SObjectType stype : gd.values()){
                Schema.DescribeSObjectResult r = stype.getDescribe();
                String prefix = r.getKeyPrefix();
                System.debug('Prefix is ' + prefix);
                 
                //Check if the prefix matches with requested prefix
                if(prefix!=null && prefix.equals(myIdPrefix)){
                    objectName = r.getName();
                    System.debug('Object Name! ' + objectName);
                    break;
                }
            }
        }catch(Exception e){
            System.debug(e);
        }
        return objectName;
    }
}

Please below post for more detail.
https://help.salesforce.com/apex/HTViewSolution?urlname=How-to-find-Object-Type-from-Record-ID-Prefix&language=en_US (https://help.salesforce.com/apex/HTViewSolution?urlname=How-to-find-Object-Type-from-Record-ID-Prefix&language=en_US)

NOTE:- Prefix for standard object will be same in all org but custom object can be differnt. you can try below code to get custom object prefix.


Schema.DescribeSObjectResult r = CustomObject__c.sObjectType.getDescribe();
String keyPrefix = r.getKeyPrefix();
System.debug('Printing --'+keyPrefix );


Please mark this as solution if this will help you. So that if some one has same issue this post can help other also.

Thanks,
Amit Chaudhary
ManojjenaManojjena
Hi B kId,

All sObject ( satndard or custom) record in Salesforce is either 15 or 18 digid . The first 3 digid of the record id represents the Object .

Technically it says keyPrefix .You can get eaisly in console by using below  code .
 
String keyPrefix= Opportunity.SObjectType.getDescribe().getKeyPrefix();
System.debug('*******************'+keyPrefix);

Replace Opportunity with other object and observe the magic .

Let me know if it helps !!
Thanks 
Manoj