I am unable to fetch recortype in lightning component. Can anyone help me tell where is the issue
Code for component
<aura:component controller="EMTEventCreationWizardController" implements="lightning:actionOverride,force:lightningQuickAction,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,lightning:isUrlAddressable" access="global" >
<aura:attribute name="recordId" type="Id"/>
<aura:attribute name="recordTypeId" type="String" />
<aura:attribute name="ObjectName" type="String" default="Events__c" access="global"/>
<aura:attribute name="eventRecordType" type="String"/>
<aura:if isTrue="{!equals(v.eventRecordType,'Internal Event')}">
<c:EMT_InternalEvent recordTypeId="{!v.recordTypeId}" eventRecordType="{!v.eventRecordType}" ObjectName="{!v.ObjectName}" recordId="{!v.recordId}"/>
</aura:if>
<aura:if isTrue="{!equals(v.eventRecordType,'External Event')}">
<c:EMT_ExternalEvent recordTypeId="{!v.recordTypeId}" eventRecordType="{!v.eventRecordType}" ObjectName="{!v.ObjectName}" recordId="{!v.recordId}"/>
</aura:if>
here is the code for my controller
doInit : function(component, event, helper) {
var recordTypeId = component.get("v.pageReference").state.recordTypeId
console.log("recordType is "+recordTypeId);
component.set('v.recordTypeId',recordTypeId);
helper.fetchRecordTypeName(component);
}
Here is the code for helper
fetchRecordTypeName: function(component,event) {
var action = component.get("c.getRecordTypeNameById");
action.setParams({
'objectName': component.get("v.ObjectName"),
'strRecordTypeId': component.get('v.recordTypeId'),
});
action.setCallback(this, function(response) {
component.set("v.eventRecordType", response.getReturnValue());
});
$A.enqueueAction(action);
}
Here is the code for apex controller
public static String getRecordTypeNameById(String objectName, Id strRecordTypeId)
{
return Schema.getGlobalDescribe().get(objectName).getDescribe().getRecordTypeInfosById().get(strRecordTypeId).getName();
}
Kindly let me know where i am getting it wrong
when i am trying to display recordtypeId to console from controller the value i get is undefined