You need to sign in to do that
Don't have an account?
Dave Craigmile
Imperative Apex Hook
Newbie question. I have a simple LWC component where I am using imperative apex to return a List<Custom Apex Class> that is not wired or cacheable. I want to immediately display this data in the component.
What "hook" should I use to invoke my imperative apex?. Here is my current code but I have got to believe there is an easier way to display data on the 'open' of a component when you cannot use @wire or the other pre-cooked approaches.
import { LightningElement, api, wire } from 'lwc';
import getStatusList from '@salesforce/apex/BrokerLoadStatus2Controller2.getStatusList';
export default class BrokerLoadStatus extends LightningElement {
@api recordId;
statusList;
error;
constructor() {
super();
this.firstTime = true;
}
renderedCallback() {
if(this.firstTime) {
this.getLoadStatus();
this.firstTime = false;
}
}
getLoadStatus() {
getStatusList({loadId: this.recordId})
.then(result => {
this.statusList = result;
this.error = undefined;
})
.catch(error => {
this.statusList = undefined;
this.error = error;
});
}
}
// EOF
What "hook" should I use to invoke my imperative apex?. Here is my current code but I have got to believe there is an easier way to display data on the 'open' of a component when you cannot use @wire or the other pre-cooked approaches.
import { LightningElement, api, wire } from 'lwc';
import getStatusList from '@salesforce/apex/BrokerLoadStatus2Controller2.getStatusList';
export default class BrokerLoadStatus extends LightningElement {
@api recordId;
statusList;
error;
constructor() {
super();
this.firstTime = true;
}
renderedCallback() {
if(this.firstTime) {
this.getLoadStatus();
this.firstTime = false;
}
}
getLoadStatus() {
getStatusList({loadId: this.recordId})
.then(result => {
this.statusList = result;
this.error = undefined;
})
.catch(error => {
this.statusList = undefined;
this.error = error;
});
}
}
// EOF
Thanks
Yogesh Rao