How to pass record id from aura component to lightning web component in Salesforce?

How to pass record id from aura component to lightning web component in Salesforce?

Sample code:

Lightning Aura Component:

<aura:component implements = "force:lightningQuickActionWithoutHeader,force:hasRecordId">  
    <c:sampleLWC recId="{!v.recordId}"/> 
</aura:component>   

Lightning Web Component HTML:

<template>  
    Test - {recId} 
</template>  

Lightning Web Component JavaScript:

import { LightningElement,api } from 'lwc';  
 
export default class PrintNotesLWC extends LightningElement {  
 
    @api recId; 
 
}  

Lightning Web Component JavaScript meta.xml:

<?xml version="1.0" encoding="UTF-8"?>  
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata" fqn="PrintNotesLWC">  
    <apiVersion>46.0</apiVersion> 
    <isExposed>false</isExposed>     
    <targets>   
        <target>lightning__RecordPage</target>   
    </targets>   
    <targetConfigs>   
        <targetConfig targets="lightning__RecordPage">   
            <property name="recId" type="String" label="Record Id" description="Record Id"/>   
        </targetConfig> 
    </targetConfigs>     
</LightningComponentBundle>  

Output:

Leave a Reply