1

I have a simple LWC component that isn't able to perform getRecord. As in the situation in this question, I need it to be invoked in a quick action, so it's wrapped in an aura component (if that matters). Here is the js:

import { LightningElement, api, wire } from "lwc";
import { getRecord } from "lightning/uiRecordApi";

const oppFields = ["Opportunity.Name"];

export default class testOPP extends LightningElement {
  @api recordId;

  // Fetch fields of current opportunity.
  @wire(getRecord, { recordId: "$recordId", oppFields })
  opp;
  renderedCallback() {
    console.log("in callback");
    console.log("recordId: " + JSON.stringify(this.recordId));
    console.log("Opp: " + JSON.stringify(this.opp));
    console.log("Opp data: " + JSON.stringify(this.opp.data));
  }
}

And here is the markup:

<template>
    In my template
    Record Id is : {recordId}
    <br />
    <template if:true={opp.data}>
        {opp.data.fields.Name.value}
    </template>
</template>

The console shows that recordId is getting populated, but the renderedCallback is only called once. I thought it was supposed to be called several times until the data is pulled down. Here is the console log:

in callback
recordId: "006M000000MGcpvIAD"
Opp: {}
Opp data: undefined

Thanks in advance for any thoughts!

  • Randy

1 Answer 1

2

A small grammar error:

@wire(getRecord, { recordId: "$recordId", oppFields })

Defines a property oppFields on the parameters, but it needs to be fields:

@wire(getRecord, { recordId: "$recordId", fields: oppFields })
2
  • That did the trick! Big thanks, @sfdxfox. (Don't have reputation points so can't upvote.) Commented May 11, 2020 at 14:43
  • @RandyTrigg You can click the ✅ to mark it as an answer, which will give you some reputation. Also, I forgot to give you a +1, so there you go.
    – sfdcfox
    Commented May 11, 2020 at 14:49

You must log in to answer this question.

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