Another Salesforce blog!!!

Salesforce, Apex

HOW TO GET LIST OF RECORD TYPE FOR THE OBJECT


How to get the record type name/id:

Map<String, Id> mapOfRecordTypeAndId = getMapOfRecordTypeAndId('EMPLOYEE__c');
system.debug('//' + mapOfRecordTypeAndId);

system.debug('// id of the record type' + mapOfRecordTypeAndId.get('recordtypename');

Util class:

public static Map<String,Id> getMapOfRecordTypeAndId(String sObjectName){
        Map<String , Id> mapOfRecordTypeAndId = new Map<String , Id>();
        if (object_recordtypes.containsKey(sObjectName) && object_recordtypes.get(sObjectName).size()>0 ){
            mapOfRecordTypeAndId= object_recordtypes.get(sObjectName);
        }else{
            List<RecordType> recordTypeList = [SELECT Id, Name, DeveloperName FROM RecordType WHERE SobjectType =:sObjectName LIMIT 100];
            if(recordTypeList != null && recordTypeList.size() > 0){
                for(RecordType recTyp:recordTypeList){
                    mapOfRecordTypeAndId.put(recTyp.DeveloperName, recTyp.Id);
                }
            }
            object_recordtypes.put(sObjectName, mapOfRecordTypeAndId);
        }
        return mapOfRecordTypeAndId;
    }

Leave a Reply

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

*