+ Start a Discussion
Raksha JhaRaksha Jha 

How to pass record Id to Record view form and lightning datatable on button click?

I have two object Auction(master) and Bid(child). i have used lightning datatable(Aura) to display bid history and record-view form(LWC) to display related auction record. my question is how can I pass the record Id from the Auction detail page to my both the components when someone will click the bid history button on detail page?

Thank You! 
Best Answer chosen by Raksha Jha
Amer WilsonAmer Wilson
Hi Raksha Jha,

I saw you have solved your problem, but I thought I would share any tips just incase you face anything like this again in the future. Or incase anyone else faces this and needs a solution. 

You can access the record Id in both of your components(Aura and LWC), irrespective of Bid History button is clicked or not. This means record id will always be available in your component whenever your component will get invoked in a record context in Lightning Experience.

Please follow the following steps to get the record id in your component.

For Aura component
You just need to add following line in the aura component
<aura:component implements="force:hasRecordId">

To fetch the record Id in the JS controller
var idValue=component.get("v.recordId");
Review this link for more detail (https://developer.salesforce.com/docs/component-library/bundle/force:hasRecordId/documentation)

For LWC you could also take the benefit from the salesforce provided way. In the component’s JavaScript class, use the @api decorator to create a public recordId property like:
@api recordId;

When your component is invoked in a record context in Lightning Experience or in the mobile app, recordId is set to the 18-character ID of the record, for example 001xx000003DGSWAA4
Review this link for more detail (https://developer.salesforce.com/docs/component-library/documentation/en/lwc/lwc.use_record_context)

Let me know if you have any further queries.

All Answers

Piyush jadavPiyush jadav

Hi Raksha

It would be great if you share your code. not able to understand your problem.

Raksha JhaRaksha Jha
thank your response ... i got it solved by implementing "force:hasRecordId " interface in my datatable.
https://developer.salesforce.com/docs/component-library/bundle/force:hasRecordId/documentation
Thanks again!
Amer WilsonAmer Wilson
Hi Raksha Jha,

I saw you have solved your problem, but I thought I would share any tips just incase you face anything like this again in the future. Or incase anyone else faces this and needs a solution. 

You can access the record Id in both of your components(Aura and LWC), irrespective of Bid History button is clicked or not. This means record id will always be available in your component whenever your component will get invoked in a record context in Lightning Experience.

Please follow the following steps to get the record id in your component.

For Aura component
You just need to add following line in the aura component
<aura:component implements="force:hasRecordId">

To fetch the record Id in the JS controller
var idValue=component.get("v.recordId");
Review this link for more detail (https://developer.salesforce.com/docs/component-library/bundle/force:hasRecordId/documentation)

For LWC you could also take the benefit from the salesforce provided way. In the component’s JavaScript class, use the @api decorator to create a public recordId property like:
@api recordId;

When your component is invoked in a record context in Lightning Experience or in the mobile app, recordId is set to the 18-character ID of the record, for example 001xx000003DGSWAA4
Review this link for more detail (https://developer.salesforce.com/docs/component-library/documentation/en/lwc/lwc.use_record_context)

Let me know if you have any further queries.
This was selected as the best answer