2

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;
    } 
}
1
  • 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
    Commented Jul 10, 2019 at 19:36

2 Answers 2

1

The reason was:

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

import TRIP_CODE_FIELD from '@salesforce/schema/{SObject}.Trip_TripCode__c';

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .