I have an Account lookup field which gets Account ID, and need to get its Account Name on field change. (This is a Home tab component using Opportunity Form)
HTML (lightning-record-edit-form; object-api-name = Opportunity)
<lightning-input-field field-name={oppAccountField} onchange={handleAccountChange} required></lightning-input-field>
JS
accountId = '';
@wire(getRecord, {
recordId: '$accountId',
fields: [ ACCOUNT_NAME_FIELD ]
})
thisAccount({ error, data }) {
if (data) {
console.log('got data');
this.accountName = getFieldValue(data, ACCOUNT_NAME_FIELD);
}
if (error) {
console.log('error');
handleError(error);
}
}
handleAccountChange(e) {
this.accountId = getFieldValue(e.detail.value, ACCOUNT_ID_FIELD);
console.log('new acc Id: ' + this.accountId); //shows correct id
}
Tis updates the this.accountId with accurate id, but does not @wire getRecord. Also, the getRecord works perfectly if I just hardcode random Id inside handleAccountChange(), but not even error console log runs after assigning accountId through getFieldValue. Please tell me what am I doing wrong?