Reputation: 31
I tried to build a LWC component to view data, but the data was not showing on UI. i can't get what was wrong with my code.
Html:
<template>
<lightning-card title="LDS Lab" icon-name="custom:custom54">
<div class="slds-m-around_small">
<lightning-record-form
record-id={recordId}
object-api-name={objectApiName}
layout-type="full"
mode="view"
columns="2"
>
</lightning-record-form>
</div>
</lightning-card>
</template>
JavaScript:
import { LightningElement,api } from 'lwc';
export default class LdsRecord extends LightningElement {
@api recordId;
@api objectApiName;
}
Meta File:
<?xml version="1.0" encoding="UTF-8"?><LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>52.0</apiVersion>
<isExposed>true</isExposed>
<targets>
<target>lightning__RecordPage</target>
</targets>
</LightningComponentBundle>
Upvotes: 0
Views: 5103
Reputation: 39
First thing you need to check here is if you are getting recordId before the LDS form get loads, if it is not having blank value while loading then try below.
Using getter setters to set the recordId attribute
Add a console log in getter if the _recordId is having value
If not then use a boolean to avoid lightning-record-form load, if:true=attribute
And load it when you have recordId in getter.
load = false;
@api set recordId(value) {
console.log(value);
this._recordId = value;
load = true
}
get recordId() {
console.log(this._recordId);
return this._recordId;
}
Please check this post also: https://salesforce.stackexchange.com/questions/344045/recordid-is-undefined-in-lwc-quick-action-component
Upvotes: 0