• Michael Muchow
  • NEWBIE
  • 10 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 2
    Replies
Hi guys,
I'm trying to wire a function as described here (https://developer.salesforce.com/docs/component-library/documentation/lwc/lwc.data_wire_service_about).

This is my code:
 
@wire(getRecord, { recordId: '$recordId', fields: ['Lead.Name'] })
    wiredRecord({ error, data}){
        if (data) {
            this.record = data;
            this.error = undefined;
        } else if (error) {
            this.error = error;
            this.data = undefined;
        }
        console.log('test '+JSON.stringify(this.record));
    };

get test() { 
    return this.record.fields.Name.value; 
}
Everything works fine and I got the following log of the data:
{"apiName":"Lead","childRelationships":{},"fields":{"Name":{"displayValue":null,"value":"Test Name"}},"id":"00Q0D000001njilUAA","lastModifiedById":"005240000052XZeAAM","lastModifiedDate":"2019-03-21T13:41:40.000Z","recordTypeInfo":{"available":true,"defaultRecordTypeMapping":true,"master":false,"name":"Customer","recordTypeId":"01224000000SVMWAA4"},"systemModstamp":"2019-03-21T13:41:40.000Z"}
If I want to access the value like it described in the link (e.g. this.record.fields.Name.value;) with this.record.fields.Name.value; I get the error:

Cannot read property 'fields' of undefined

What is wrong and why can't I access the fields/value?

 

Hi guys,
I have a Lightning Web Component, this component sits on the Record Page and gets the record id by import { getRecord } from 'lightning/uiRecord';

With this id and some Custom Metadata I query some data of this record by an apex class and give it back to the template to show it.

Now I want to refresh/call the apex class again to get the updated data if the record was updated.

How can I do this?