A logistics company builds an LWC for the Shipment__c record page. It must call an imperative Apex method that needs the recordId as soon as the component is inserted into the DOM. Where should the developer place the call?
- In the constructor(), right after calling super()
- In connectedCallback(), which runs when the component is inserted into the DOM
- In renderedCallback(), guarded by no additional logic
- In disconnectedCallback(), so the call completes before rendering
Show answer
Answer: B
Why: connectedCallback() is the lifecycle hook for one-time initialization that depends on public properties, such as calling Apex or subscribing to a message channel. The constructor runs too early to read values passed in by the owner.