I have one LWC component. In my JS file, I'm trying to call one apex method imperatively as it is not cache enabled, based on the result of wired method.
I'm not receiving the result of my wired method, as it is not executed at that time. I tried to call my imperative method in connectedCallback(), even at that time also my wired method data is not available.
What other options I have to call my imperative method after getting data from the wired method?
JS:
import ACCOUNT_ID from "@salesforce/schema/User.AccountId";
import checkActives from '@salesforce/apex/AcitveService.checkActives';
// this gets you the logged in user
import USER_ID from "@salesforce/user/Id";
@wire(getRecord, { recordId: USER_ID, fields: [ACCOUNT_ID] })
wiredRecord({ error, data }) {
if (error) {
} else if (data) {
let accId = data.fields.AccountId.value;
checkActive({accountId: accId})
.then(result => {
if(result.hasActive){
this.displayActiveMessage = false;
}else{
this.displayActiveMessage = true;
this.displayCaseCreation = false;
}
})
.catch(error => {
console.log('>>> error... '+JSON.stringify(error));
});
}
}
Edit: USER_ID is the logged in USER ID
UserInfo.getUserId()
.