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 })
  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:

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

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

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 })
  • That did the trick! Big thanks, @sfdxfox. (Don't have reputation points so can't upvote.) – Randy Trigg May 11 '20 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 May 11 '20 at 14:49

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.