function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Denise CrosbyDenise Crosby 

lightning component to override standard action can't use force:hasRecordId

I created a lightning component to override the standard "new" opportunity. The problem is that when I implement the force:hasRecordId interface, the recordId shows in my debugger as "undefined". I need to use the current id of the account or contact to pre-populate fields in my component. How can I do this?

Here is the documentation I found, which seems to explain that recordId is undefined in my situation.

The recordId attribute is set only when you place or invoke the component in an explicit record context. For example, when you place the component directly on a record page layout, or invoke it as an object-specific action from a record page or object home. In all other cases, such as when you invoke the component as a global action, or create the component programmatically inside another component, recordIdisn’t set, and your component shouldn’t depend on it.
These unsupported contexts include a few contexts that might seem like they should have access to the current record. Examples of these other contexts include the following:
Invoking the component from a global action (even when you’re on a record page)
Invoking the component from header or footer navigation in a community (even if the page shows a record)
force:hasRecordId and force:hasSObjectName are unsupported in these contexts. While the marker interfaces still add the relevant attribute to the component, accessing either attribute generally returns null or undefined.

Thanks for helping.
Suresh RaghuramSuresh Raghuram
Hi Denise,

Did you get any solution for this, I am trying to override the related record button and I am not able to access the parent record Id to populate the lookup on child record.
Please let me know if you came across any solution.

Suresh R
Rajesh Varma MudunuriRajesh Varma Mudunuri
Please do vote for this idea, for truly context aware lightning components.
Rajesh Varma.
Alain CabonAlain Cabon
Hi Denise,

Your question is now one of the most popular for Lightning.

The marker interfaces like force:hasParentId and force:hasParentObjectName are still missing as Rajesh Varma Mudunuri stated above and I didn't find a solution but just workarounds.

The workarounds to which you have surely already thought of, are:

1) by creating a new related list that is itself a component with a datatable (expensive workaround) but here the standard related list of opportunities in the object Account is a complicated component that is difficult to reproduce in a custom Lex component. 
I reproduced and tested a related list with a lex component using <lightning:datatable> at work and this component will be always the first or the last related list (on top or on bottom of the standard component of related lists in the Lex page). Finally, I never used it in production.

2) by adding a new custom action button "New Opportunity" on the top of the page of the account (among the other buttons and actions of the account, inexpensive workaround) and by removing the "New" button for the related list of opportunities in the account.

Best regards