Lightning – Overriding ‘New’ Standard Action with Different Record Types

I'm trying to overrides the standard 'New' action on one of my custom object.

enter image description here

First of all, as you can see from the above picture, the 'Skip Record Type Selection Page' checkbox doesn't seem to work. When I uncheck this checkbox, I still have a visualforce page asking to select a record type. The weirder part is that the standard Lightning record type selection is replaced by a Visualforce page. See the below picture.

enter image description here

On the other hand, it's impossible to get the record type which was selected previously. Whereas the selected record type id appears on the url like this: https://lgc-bfl--dev2.lightning.force.com/one/one.app#/sObject/LGC_Ligne_bordereau__c/new?recordTypeId=0129E00000008zP.

I tried to declare it as attribute:

<aura:attribute name="recordTypeId" type="String" />

Then access it from my controller:

console.log(component.get("v.recordTypeId"));

But the attribute is undefined.

How am I supposed to know which record type was selected? If this is not possible, why can't I remove the record type selection and handle it myself?

Best Answer

I was facing similar issue then as a workaround I am using javascript to fetch the Id and then passing in my controller.

var url_string = window.location.href;
console.log(url_string.substring(url_string.indexOf("recordTypeId") + 13,url_string.indexOf("recordTypeId") + 28));
Related Topic