Lightning Web Component Get the record Id
Record id denotes the unique id of any object record.To get the record id in LWC is very easy we just have to use the @api decorator to get the record id.
Syntax: @api recordId
import { LightningElement, api } from 'lwc'; export default class salesforce driller extends LightningElement { @api recordId; }
recordId is the property that uses the api public decorator to get the record ID.
Let’s play with the code
salesforcedriller.html
<template> This is the record id it returns through api decorator with recordId property. <br/>Record Id: {recordId} </template>
Salesforcedriller.js
import {LightningElement,wire, api} from 'lwc'; import {NavigationMixin} from 'lightning/navigation'; export default class salesforcedriller extends NavigationMixin(LightningElement) { @api recordId; }
Output
Add your component to any of your record details page (contact, account etc).