Play Games

Search This Blog

Tuesday, May 25, 2021

Get recordId in the lwc component - Salesforce Globe For You

 Get recordId in the lwc component  - Salesforce Globe For You 

Solution: Use the recordId property in the lwc javascript file.

When this component is used on the lightning record page,the page automatically sets the recordId property with the ID of the current record.

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