To display a record in a Lightning web component (LWC), you can use the lightning-record-form component and pass in a record Id. Here's a simple explanation of how to do it:
If you just need to display the record with default output fields, use the lightning-record-form component with record-id attribute set to the Id of the record you want to display.
If you need a custom layout, use lightning-record-view-form instead of lightning-record-form.
If you need even more customization than the form-based components allow, you can use a wire adapter like getRecord to load the record data and then manually render it in your LWC.
In lightning-record-form, you can display a record in two modes - view and read-only. View mode is the default when record-id is provided. In view mode, the form loads with output fields and inline editing enabled. If a user clicks an edit icon, all fields in the form become editable, and the form displays Submit and Cancel buttons. In read-only mode, the form loads with output fields only and doesn't include edit icons or Submit and Cancel buttons.
HTML
<template>
<lightning-record-form
record-id={recordId}
object-api-name={objectApiName}
fields={fields}>
</lightning-record-form>
</template>
Java Script
import { LightningElement, api } from 'lwc';
export default class MyComponent extends LightningElement {
@api recordId;
@api objectApiName;
fields = ['AccountId', 'Name', 'Title', 'Phone', 'Email'];
}
In this example, record-id is set to the Id of the account record you want to display, object-api-name is set to "Account" to indicate the object type, fields is set to the list of fields you want to display, and mode is set to "view" to indicate the view mode.
Video
Video does not exists.
Mastered by 16 users.