buli
2023-04-26 d6a096fadfe9c8f261f56a827cfceed663c36b8b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { LightningElement, wire } from 'lwc';
import { formatApexSObjects } from 'c/apexUtils';
import getAccounts from '@salesforce/apex/ListWithParentRecordDataControllerLwc.getAccounts';
import ACCOUNT_NAME_FIELD from '@salesforce/schema/Account.Name';
import ACCOUNT_TYPE_FIELD from '@salesforce/schema/Account.Type';
import ACCOUNT_PHONE_FIELD from '@salesforce/schema/Account.Phone';
import ACCOUNT_OWNER_NAME_FIELD from '@salesforce/schema/Account.Owner.Name';
 
const COLUMNS = [
    {
        label: 'Account Name',
        fieldName: ACCOUNT_NAME_FIELD.fieldApiName,
        type: 'text'
    },
    { label: 'Type', fieldName: ACCOUNT_TYPE_FIELD.fieldApiName, type: 'text' },
    {
        label: 'Phone',
        fieldName: ACCOUNT_PHONE_FIELD.fieldApiName,
        type: 'phone'
    },
    {
        label: 'Owner Name',
        fieldName: ACCOUNT_OWNER_NAME_FIELD.fieldApiName,
        type: 'text'
    }
];
 
export default class ListWithParentRecordData extends LightningElement {
    columns = COLUMNS;
 
    @wire(getAccounts)
    accounts;
 
    // Needed only when bringing parent records data
    get formattedAccounts() {
        return this.accounts.data ? formatApexSObjects(this.accounts.data) : [];
    }
}