[SalesForce] LWC / Get fields values with getRecord and wire

I can't get fields values with getRecord adapter.
Component shows passed recordId only.

Where is the problem?

enter image description here

Parent HTML:

<template>
    <lightning-card title="My Trips">
        Parent component begins here:<br />
        <template if:true={trips.data}>
            Total trips  - {trips.data.length}
            <template for:each={trips.data} for:item="trip">
                <div key={trip.Id}>
                    <c-trip-list-item recordid={trip.Id}></c-trip-list-item>
                </div>
            </template>
        </template>
            </lightning-card>
</template>

Parent JS:

import getTrips from '@salesforce/apex/tripController.getTrips';
export default class TripList extends LightningElement {
      @wire(getTrips) trips;
}

Child HTML:

<template>
    Child component begins here:<br />
    {recordid} {record.data} {record.error}
    <template if:true={record.data}>
        - {name} - {status}
    </template>
</template>

Child JS:

import { LightningElement, api, wire } from 'lwc';
import { getRecord } from 'lightning/uiRecordApi';
const FIELDS = [
    'Trip__c.Trip_TripCode__c',
    'Trip__c.Trip_Status__c',
    'Trip__c.Name',
];

export default class TripListItem extends LightningElement {

    @api recordid;
    @wire(getRecord, { recordId: '$recordid', fields: FIELDS })
    record;

    get recorddata() {
        return this.record.data;
    }
    get name() {
        return this.record.fields.Name.value;
    }

    get status() {
        return this.record.fields.Trip_Status__c.value;
    }

    get code() {
     return this.record.fields.Trip_TripCode__c.value;
    } 
}

Best Answer

The reason was:

get code() {
     return this.record **.data**. fields.Trip_TripCode__c.value;
    } 
Related Topic