0

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;
    } 
}
  • I suggest you answer your own question to explain that the various paths in the get methods were missing the ".data" after ".record". – Phil W Jul 10 at 19:36
0

The reason was:

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

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.