0

I am new to Lightning Web Components. I wanted to know how the @api recordId gets the recordId from the record. If I change it to @api recId, the code does not work.

Does the api fetch the recordId in it just because the name of the public property is recordId? How does it happen? I did not find a satisfactory answer to this question.

<!-- myComponent.html -->
<template>
    <lightning-record-form
        record-id={recordId}
        object-api-name="Account"
        layout-type="Compact"
        mode="view">
    </lightning-record-form>
</template> 



// myComponent.js
import { LightningElement, api } from 'lwc';
export default class MyComponent extends LightningElement {
    @api recordId;
}
1
3

Yes, recordId is a special keyword when used with @api in the context of a record page. There are others like objectApiName.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.