I am fetching some recordtype values as a string array. I want to add the string -- None-- to the array so its obvious nothing is selected by default. How do I achieve this.
I tried the following but this returns a number and all my recordtypelabels are lost. Component
<aura:handler name="init" value="{!this}" action="{!c.fetchListOfRecordTypes}"/>
<aura:attribute name="lstOfRecordType" type="String[]"/>
<aura:attribute name="genericObject" type="String" />
<aura:attribute name="selectedValue" type="String" default="Hoofd"/>
<!-- Model Box Start -->
<div role="dialog" tabindex="-1" aria-labelledby="header43" >
<div class="slds-grid slds-wrap">
Select a Record Type<br/>
<ui:inputSelect aura:id="selectid" required="true">
<aura:iteration items="{!v.lstOfRecordType}" var="rectype">
<ui:inputSelectOption text="{!rectype}" label="{!rectype}" />
</aura:iteration>
</ui:inputSelect>
<lightning:button class="slds-button slds-button-#brand" onclick="{!c.createRecord}">Next</lightning:button>
</div>
</div>
Javascript
fetchListOfRecordTypes : function(component, event, helper) {
var genericObject = component.get("v.genericObject");
var action = component.get("c.fetchRecordTypeValues");
action.setParams({ "objectStr" : genericObject });
action.setCallback(this, function(response) {
var state = response.getState();
if (state === "SUCCESS") {
// Fetch recordtypes
action.setCallback(this, function(response) {
component.set("v.lstOfRecordType", response.getReturnValue().push("--None--"));
});
$A.enqueueAction(action);
}
else {
console.log(state);
}
});
$A.enqueueAction(action);
}
Apex
public class recordtypeSelector {
public static Map<Id, String> recordtypemap {get;set;}
@AuraEnabled
public static List<String> fetchRecordTypeValues(string objectStr){
SObjectType sObjType = ((SObject) Type.forName(objectStr).newInstance()).getSObjectType();
List<Schema.RecordTypeInfo> recordtypes = sObjType.getDescribe().getRecordTypeInfos();
recordtypemap = new Map<Id, String>();
for(RecordTypeInfo rt : recordtypes){
if(rt.getName() != 'Master')
recordtypemap.put(rt.getRecordTypeId(), rt.getName());
}
return recordtypemap.values();
}
@AuraEnabled
public static Id getRecTypeId(String recordTypeLabel, string objectStr){
system.debug('recordTypeLabel: '+recordTypeLabel);
system.debug('objectStr: '+objectStr);
Id recid = Schema.getGlobalDescribe().get(objectStr).getDescribe().getRecordTypeInfosByName().get(recordTypeLabel).getRecordTypeId();
system.debug('recid: '+recid);
return recid;
}
}
component.set("v.lstOfRecordType", [...response.getReturnValue() , "--None--"]);