I'm having trouble using @wire for example to get a single field from an object detail and passing it in to the async connected callback for a query. I need to get some data from a related list on another table and am wondering if I could achieve this with the out of the box lwc stuff or if I am gonna have to write some more specific apex logic to handle the query. I'm reading through the docs and seeing something to the effect of wrapping both method wire? I also have auraEnabled(cacheable=true) to run it on mount(?). The code is something like:
import { LightningElement, api, track, wire } from 'lightning';
import LOOKUP_FIELD from '@salesforce/schema/Account.Lookup__c';
import { getRecord, getFieldValue } from 'lightning/uiRecordApi';
import getData from '@salesforce/apex/Util.getData';
const fields = [ LOOKUP_FIELD ];
export default class TestComponent extends LightningElement {
@api recordId;
@track data;
@wire( getRecord, { recordId:`$recordId`, fields } )
account; // happens later
async connectedCallback() {
// happens first
const lookup = this.lookup;
this.data = await getData({ lookup }).catch(err => console.log(err));
}
get lookup() {
return getFieldValue(this.account.data, LOOKUP_FIELD);
}
}