[SalesForce] Passing ID from Parent Aura to LWC

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;
    }
}

Best Answer

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

Related Topic