How do I access a list of all of either the values or ids in a map? I thought just this.recTypeChoices.values would work but it does not. Here is my javascript setting the values in the map.
// 1. get list of opportunity record types to display for selection
getRecordTypeMap({sObjectName: this.sObjectType, oppTypes: this.oppTypes})
.then(data => {
this.recTypeChoices = Object.keys(data).map(key => ({
label: key,
value: data[key]
}));
})
.catch(error => {
console.log('FAIL here is error ' + JSON.stringify(error));
this.dispatchEvent(
new ShowToastEvent({
title: 'Error!!',
message: error.message,
variant: 'error',
}),
);
this.isLoading = false
});
When I console.log this.recTypeChoices I get the following result:
here are the this.recTypeChoices.values [{"label":"New Business Dental","value":"012700000001e8XAAQ"},{"label":"New Business Dental Voluntary","value":"012700000001fK5AAI"},{"label":"New Business Health","value":"012700000001e8YAAQ"},{"label":"New Business Prescription","value":"012700000001e8ZAAQ"},{"label":"New Business Vision","value":"012700000001e8aAAA"},{"label":"New Business Vision Voluntary","value":"012700000001fK6AAI"}]
Apex is as follows:
//method to return record type name and Id
@AuraEnabled(cacheable=true)
public static Map<string, id> getRecordTypeMap(String sObjectName, String oppTypes){
List<RecordType> rtList = new List<RecordType>();
//if the request is for the main record types
if(oppTypes == 'Main New Business') {
rtList = [
select id, name
from RecordType
where (SObjectType = : sObjectName and (Name = : 'New Business Health' OR Name = : 'New Business Prescription' or Name = : 'New Business Dental'
or Name = : 'New Business Dental Voluntary' or Name = : 'New Business Vision' or Name = : 'New Business Vision Voluntary'))];
}
Map<String, Id> recordTypeMap = new Map<String, Id>();
for(RecordType rti : rtList) {
recordTypeMap.put(rti.Name, rti.Id);
}
return recordTypeMap;
}