Get sObject prefix

 Pass object name in method parameter.

***

public static void getPrefix(String objName){

        Schema.sObjectType sObjType = Schema.getGlobalDescribe().get(objName);

        String prefixValue = (sObjType.getDescribe().getKeyPrefix());

        System.debug('prefixValue##' + prefixValue);

    }

***

OR you can get prefix value from here

***

Schema.DescribeSObjectResult r = Account.sObjectType.getDescribe();

String keyPrefix = r.getKeyPrefix();

System.debug('keyPrefix##' + keyPrefix);

***

Replace Account object from your object name.

Comments

Popular posts from this blog

Get current user information in apex

Get picklist values in apex

Show only DML exception message from parent exception