0

I am new to the salesforce and record type:

Map<Id,RecordType> caseRTMap = new Map<Id, RecordType>([SELECT Id, DeveloperName 
                                                                FROM RecordType WHERE SObjectType = 'Case']);
System.debug('caseRTMap : '+caseRTMap);
List<RecordType> lst = caseRTMap.values();
System.debug('lst : '+lst[1]);

Output is :{Id=012c00XXXXXX, DeveloperName=AAA}

How can I get the value of DeveloperName ?

2

3 Answers 3

2

You can get record Type name:

  List<RecordType> caseRT = [SELECT Id, DeveloperName FROM RecordType WHERE SObjectType = 'Case'];
  System.debug('caseRT : '+caseRT );
  for(RecordType  rt: caseRT) {
      System.debug('Case Record Type : ' + rt.DeveloperName );
  }

Or if you want to use Map:

    Map<Id, RecordType> caseRTMap = new Map<Id, RecordType>([
        SELECT Id, DeveloperName
        FROM RecordType
        WHERE SObjectType = :'Case'
]);
System.debug('caseRTMap : ' + caseRTMap);
if (caseRTMap != null && caseRTMap.size() > 0) {
    Set<Id> rtIds = caseRTMap.keySet();
    for(Id recordTypeId : rtIds) {
        System.debug('Record Type Name: ' + caseRTMap.get(recordTypeId).DeveloperName);
    }
}
2

Before using the [] nottation, ensure that the list is not empty otherwise you will get List Index out of Bound Exception.

To get the Developer name,

System.debug('lst : '+lst[1].DeveloperName)
0

Could you not use:

Map<Id,RecordType> caseRTMap = new Map<Id, RecordType>([SELECT Id, DeveloperName 
                                                                FROM RecordType WHERE SObjectType = 'Case']);

System.debug('caseRTMap : '+caseRTMap);
if(caseRTMap.values() != null){
    List<RecordType> lst = caseRTMap.values();
    System.debug('lst : '+lst[1].DeveloperName);
}

You must log in to answer this question.