I am having a situation where I'm trying to pop an alert on an opportunity, but it's conditional based on data on the current user, and data on a custom object.
I noticed that on refreshes the alert doesn't pop consistently.
Original Approach: Produced Inconsistent Results
The idea is that the user has data used for a second server call. So I had chained together 3 components.
Parent Component - Get User Data @wire decorator to fire aura enabled apex method
|_ Child Component 1 - Check SF for specific record that has user data on it. @wire decorator to fire aura enabled apex method
|___Child Component 2 - Fire Alert if Child Component returns data
However, Parent component fires every time, but the second Child does not fire consistently.
So my thought was to try promises.
New Approach: Trying Promises
I decided I would use the connectedCallBack()
function to attempt to control the server side calls.
Essentially, server side call to get user; if user is found, fire second server side call, and then begin logic on child components. Problem: I can't get the second promise to fire in this setup. I'm sure it's a syntax issue.
HTML - Parent
<template>
<template if:true={userObj.ctmUserId}>
<c-opp-contact-phone-alert
ctm-user-id={userObj.ctmUserId}
record-id={recordId}
>
</c-opp-contact-phone-alert>
</template>
</template>
JS - Parent
connectedCallback(){
console.log('CONNECTED CALLBACK');
getCurrentUser({userId: USER_ID}).then(result => {
console.log('IN PROMISE: USER');
this.userObj.ctmUserId = result.CTM_Agent_Id__c;
return lookupExistingPhone({curUserCtmId: this.userObj.ctmUserId})
}).then((result) => {
console.log('IN LOOKUP PROMISE');
this.ctmRecord = result;
console.log(this.ctmRecord);
})
}