I'm trying to work with and understand maps. I have the following map and I don't know how to retrieve one of the results from it, can some one explain what I'm doing wrong?
Map<String, RecordType >RecTypeList = new map<String, RecordType>([select Name, id from RecordType
where sObjecttype = 'Service_call_Task__c'
AND DeveloperName IN ('Service','Alarm')]) ;
system.debug(RecTypeList);
system.debug(RecTypeList.get('Alarm'));
The first debug line returns the id of the recordtype and then the results of the SOQL Query
{0124E00000010OaQAI=RecordType:{Name=Service, Id=0124E00000010OaQAI}, 0124E00000010P9QAI=RecordType:{Name=Alarm, Id=0124E00000010P9QAI}}
I was expecting something like Alarm = 0124E00000010P9QAI
The second debug line returns a null result.
I've tried to change the map from
<String, RecordType> to <String, Id >
but i get an error:
Invalid initializer type List found for Map: expected a Map with the same key and value types, or a valid SObject List
Id alarmRecordTypeId = Service_Call_Task__c.SObjectType.getDescribe().getRecordTypeInfosByName().get('Alarm').getRecordTypeId();
This gives you the answer you want without the SOQL hit (there's a limit of 100 per transaction).