function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Dave CraigmileDave 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
yogeshRaoyogeshRao
Use connectedCallback().This gets called when a component is inserted into DOM.

Thanks 
Yogesh Rao