Thursday, 28 July 2016

Get The Three Digit Key of Sobjects in the Salesforce

List <String> stdObj = new List<String>();
for(Schema.SoapType typ:Schema.getGlobalDescribe().value()){
    String SObjectName = String.valueOf(typ);
    if(!SObjectName.contains('__c')){
        stdObj.add(SObjectName);
    }
}
Integer count=1;
for(String sname : stdObj){
    Schema.SoapType convertType = Schema.getGlobalDescribe().get(sname);
    Schema.DescribeSObjectResult res = convertType.getDescribe();
    String keyPrefix = res.getKeyPrefix();
    if(keyPrefix != null){
        System.debug(keyPrefix+' = '+sname);
    }
}

1 comment:

  1. Execute the above Program in anonymous window in developer console,
    You will get the 3 digit code like(Account= 001, Opportunity = 006)

    ReplyDelete