Force:hasRecordId interface doesn’t provide recordId from “new” button override

button-overrideslightninglightning-aura-componentsrecordrelated-list

I have two custom objects (let's call them House and Resident).

The House record page has a related list containing all related residents.

I also have two lightning components (ResidentDetails and NewResident).

NewResident is called from two places, in ResidentDetails on a different record page. As well as from the "new" button override for Resident.

NewResident implements force:hasRecordId and lightning:actionOverride (see below).

However, as it is launched in a different context (the new resident page, like so: blah.lightning.force.com/lightning/o/Resident__c/new).

My problem is, the recordId attribute doesn't contain the House record Id.

component.get("v.recordId") results in undefined in doInit.

Relevant code samples:

NewResident.cmp

<aura:component implements="lightning:actionOverride,force:hasRecordId" controller="ResidentDetailsController" access="global">
    <!--Handlers-->
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    
    <p>{!v.recordId}</p> <!--empty-->
    
    <!--A bunch of other irrelevant stuff-->
</aura:component>

NewResidentController.js

({
    doInit : function(component, event, helper) {
        console.log(component.get("v.recordId")); //logs `undefined`
    },
})

This does work if I call the component from the ResidentDetails component, but doesn't when overriding the new resident button.

Any help is appreciated! Also sorry if any of my terminology is incorrect, I'm new to Salesforce.

Best Answer

It looks like this isn't yet possible with Salesforce. The Salesforce support engineer I spoke to wasn't aware of any plans to implement the feature anytime soon.

In my specific scenario, I will have to re-implement the "related list" functionality in an aura component, which then calls the "new" component.

Related Topic