0

I received help in another post that I had to put my LWC inside an Aura component to be able to navigate to it. Now, I'm trying to get the ID that is at the Aura level to the LWC so I can then query using Apex. My Aura has an attribute that holds the account ID which I am passing to the LWC. <c:groupstructurelistLWC recordId="{!v.AId}"/> Now, how do I consume that ID on the LWC component to query the records I want to display on that LWC? Basically, the LWC is using the account ID and querying custom object records related to that account. This is what I was trying but it does not seem to be passing the account id to the apex. @wire(getgroupstructures, {accountId: '$accountId'})

Here are my imports from the js:

import { LightningElement, wire, track, api } from "lwc";

// This imports a wire adaptor that is automatically generated from your Apex method import getgroupstructures from '@salesforce/apex/GSController.getgroupstructures';

// importing to show toast notifictions import {ShowToastEvent} from 'lightning/platformShowToastEvent';

// importing to refresh the apex if any record changes the datas import {refreshApex} from '@salesforce/apex';

And here are my exports:

export default class GSList extends LightningElement {

@api recordId;

@track data;
@track columns = cols;
@track record = [];
@track bShowModal = false;
@track currentRecordId;
@track isEditForm = false;
@track showLoadingSpinner = false;

// @track groupstructures; //@track error;

@track sortDirection;

// non-reactive variables
selectedRecords = [];
refreshTable;
error;

@wire(getgroupstructures, {accountId: '$recordId'})
groupstructures(result) {
    this.refreshTable = result;
    if (result.data) {
        this.data = result.data;
        this.error = undefined;

    } else if (result.error) {
        this.error = result.error;
        this.data = undefined;
    }
}
4
  • Try recordId instead of accountId like @wire(getgroupstructures, {accountId: '$recordId'}) May 14, 2020 at 15:06
  • Thanks for the response. Unfortunately, that did not help. When I use @wire(getgroupstructures, {accountId: '$recordId'}) the apex does not run. However, this will run the apex but obviously not pass the ID I need for the query. @wire(getgroupstructures)
    – Frank
    May 14, 2020 at 15:36
  • 2
    @Fred Did you also include @api recordId in your class somewhere?
    – sfdcfox
    May 14, 2020 at 15:57
  • I do have @api recordId. I updated the question to include all of the code. thanks!!!!!
    – Frank
    May 14, 2020 at 21:49

1 Answer 1

1

You need to add @api recordId in lwc js to get Id from parent Aura to child lwc

5
  • I do. Here are my imports: /* eslint-disable no-console */ import { LightningElement, wire, track, api } from "lwc"; // This imports a wire adaptor that is automatically generated from your Apex method import getgroupstructures from '@salesforce/apex/GSController.getgroupstructures'; // importing to show toast notifictions import {ShowToastEvent} from 'lightning/platformShowToastEvent'; // importing to refresh the apex if any record changes the datas import {refreshApex} from '@salesforce/apex';
    – Frank
    May 14, 2020 at 21:44
  • Define a new method `Connectedcallback()' and console the recordId in it. May 14, 2020 at 22:17
  • And also check if class variable name same as well you call from lwc May 14, 2020 at 22:18
  • Can you share class code? May 14, 2020 at 22:19
  • I played around with it and got it to work with using recordId as the variable name. I had tried that before but I guess I either had not updated everything correctly. Thank you!!!!!
    – Frank
    May 15, 2020 at 13:09

You must log in to answer this question.

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