+ Start a Discussion
TestingSFUserTestingSFUser 

How to pass Record Id from Parent component to Child component in Aura

Hi..,
I am calling the Child component from the Parent component..so, it is successfully done.
but
along with that i want to pass the Record Id from Parent component to Child component using Aura component.
Thanks
Maharajan CMaharajan C
Hi Sukumar,

Please use the sample code:

1. Create one attribute in Child Component.
<aura:attribute name="recordId" type="String" />

2. Pass the id from parent to child like below.
<c:ChildComponent recordId="{!v.recordId}"></c:ChildComponent>

Parent Component :
<aura:component implements="flexipage:availableForAllPageTypes,force:hasRecordId" access="global" >
    <lightning:card title="Passing Id to Child">
        Parent Component Current Id - {!v.recordId}    
        <c:ChildComponent recordId="{!v.recordId}"></c:ChildComponent>
    </lightning:card>
</aura:component>

Child Component:
<aura:component implements="flexipage:availableForAllPageTypes" access="global" >
    <aura:attribute name="recordId" type="String" />
    <br/>
    Child Component Current Id - {!v.recordId}
</aura:component>

Thanks,
Maharajan.C
mukesh guptamukesh gupta
Hi Sukumar,

Please follow below code:-
 
ParentComponent.cmp
 
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
    <aura:attribute name="recordId" type="Id" />

	<h1>Hello, I am Parent Component</h1>
    
    <br/>
    <br/>
    <c:ChildComponent childValue="{!v.recordId}" />
</aura:component>
 
ChildComponent.cmp
 
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
    <aura:attribute name="childValue" type="String" />
	<h1>Hello, I am Child Component. Here is Id of Parent record : {!v.childValue}</h1>
    
</aura:component>

if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh


 
 
 
Suraj Tripathi 47Suraj Tripathi 47
Hi Sukumar,
You can use recordData in your component firstly you get the RecordId via force:hasRecordId then you can achieve the recordData in your component with that you can achieve your parentId in the same component 
Below is the given syntax.

   <force:recordData 
                      fields="CaseNumber,ParentId,AccountId,"
                      recordId="{!v.recordId}"
                      targetFields="{!v.Childcaseno}"
                      targetError="{!v.recordError}"
                      recordUpdated="{!c.handleRecordUpdated}"
                      />
Hope you find your solution
Thakns