How to get recordTypeId using record type name?

Sample Code:

        String strObject = 'Account';
        String rtName = 'Marketing';

        Schema.DescribeSObjectResult d = getDescribSObject(strObject);        
        Map<String,Schema.RecordTypeInfo> rtMapByName = d.getRecordTypeInfosByName();
        Schema.RecordTypeInfo rtByName = rtMapByName.get(rtName);
        Id recTypeId = rtByName.getRecordTypeId();

        public static Schema.DescribeSObjectResult getDescribSObject(String strObject) {
            Schema.DescribeSObjectResult d;
            if(strObject.equals('Account')) {
                        d = Schema.SObjectType.Account;


Id devRecordTypeId = Schema.SObjectType.Opportunity.getRecordTypeInfosByName().get('Advisors').getRecordTypeId();


No comments:

Post a Comment

Sharing is Caring!!! Share this with your friends!!!

submit to reddit