Notes
<template>
<lightning-datatable
key-field="Id"
data={contacts}
columns={columns}
hide-checkbox-column="true">
</lightning-datatable>
</template>
JavaScript
import { LightningElement, wire } from 'lwc';
import { getRelatedListRecords } from 'lightning/uiRelatedListApi';
export default class LdsGetRelatedListRecords extends LightningElement {
columns = [
{ label: 'Name', fieldName: 'FirstName' },
{ label: 'ID', fieldName: 'Id' }
];
contacts;
@wire(getRelatedListRecords, {
parentRecordId: '001Dn000015FGr5IAG',
relatedListId: 'Contacts',
fields: ['Contact.FirstName', 'Contact.Id']
})
wiredContacts({ error, data }) {
if (data) {
this.contacts = data.records.map(record => {
return {
Id: record.fields.Id.value,
FirstName: record.fields.FirstName.value
};
});
} else if (error) {
console.error('Error retrieving related list records: ', error);
}
}
}