How to dynamically fetch recordId in LWC salesforce - Salesforce Globe For You
Scenario: When I drag this LWC component on a particular salesforce record page(for example any account record),I need to get it's Id and display it in this LWC Component.
Solution:Use @api recordId in LWC Component.
Example:
displayRecordIdInLwc.html
<template>
<lightning-card>
<div style="padding-left: 10px;"><strong>Record Id :</strong>{recordId}</div>
</lightning-card>
</template>
displayRecordIdInLwc.js
import { LightningElement,api } from 'lwc';
export default class DisplayRecordIdInLwc extends LightningElement {
@api recordId;
}
displayRecordIdInLwc.js-meta.xml
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>51.0</apiVersion>
<isExposed>true</isExposed>
<targets>
<target>lightning__RecordPage</target>
<target>lightning__AppPage</target>
<target>lightning__HomePage</target>
</targets>
</LightningComponentBundle>
Output:
No comments:
Post a Comment