August 18, 2019

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

Sample code:

Lightning component:


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

Lightning Web Component HTML:


  1. <template>  
  2.     Test - {recId}  
  3. </template>  

Lightning Web Component JavaScript:


  1. import { LightningElement,api } from 'lwc';  
  2.   
  3. export default class PrintNotesLWC extends LightningElement {  
  4.   
  5.     @api recId;  
  6.   
  7. }  

Lightning Web Component JavaScript meta.xml:


  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata" fqn="PrintNotesLWC">  
  3.     <apiVersion>46.0</apiVersion>  
  4.     <isExposed>false</isExposed>      
  5.     <targets>    
  6.         <target>lightning__RecordPage</target>    
  7.     </targets>    
  8.     <targetConfigs>    
  9.         <targetConfig targets="lightning__RecordPage">    
  10.             <property name="recId" type="String" label="Record Id" description="Record Id"/>    
  11.         </targetConfig>  
  12.     </targetConfigs>      
  13. </LightningComponentBundle>  

Output:




No comments:

Post a Comment