• How To Get Current Record Id In LWC (Lightning Web components)

    Published By: Venu Gutta
    Published on: Sunday 3 January 2021
    A- A+

    Get Record Id dynamically in LWC

    How To Get Current Record Id In LWC -Lightning Web components Example
    In many scenarios we need to have current record id in the lightning web component. Id we want get current record id then we need to define "recordId" prublic property in corresponding lwc component JavaScript file and the lightning web component should be added into lightning record page.

     How To Fetch Current Record Id In Lightning Web component Example


    lwcGetRecordId.js
    
    import { LightningElement, api } from 'lwc';
    export default class LwcGetRecordId extends LightningElement {
        @api recordId;
    }
    
    lwcGetRecordId.html
    
    <template>
        Current Record Id : {recordId}
    </template>
    

    Output: Add above ligtning web component to any of the record page(Ex: Account, contact, opportunity....)
    How to get current record id in Lightning Web Component
  • 2 comments to ''How To Get Current Record Id In LWC (Lightning Web components)"

    ADD COMMENT
    1. have you ever checked yourself it if works..moron

      ReplyDelete
      Replies
      1. Hi Bro, Check output in above screen. BTW do you know how to write LWC components?

        Delete