Development questions
Explain the LWC lifecycle hooks and the order in which they fire for a parent and child component.
DevelopmentMedium
Hooks: constructor(), connectedCallback(), render(), renderedCallback(), disconnectedCallback(), errorCallback(error, stack).
Order when a parent contains a child:
- Parent
constructor - Parent
connectedCallback - Parent
render - Child
constructor - Child
connectedCallback - Child
render - Child
renderedCallback - Parent
renderedCallback
Notes:
- Call
super()first in the constructor; don't access attributes or children there. connectedCallbackfires when inserted into the DOM; use it to fetch data or subscribe.renderedCallbackfires after every render, so guard one-time logic with a flag.disconnectedCallbackis for cleanup (unsubscribe, remove listeners).errorCallbackcatches errors from child components in the lifecycle.
lwclifecycle
More Development questions
- What is an Apex Trigger in Salesforce and when should you use it over Flows?
- What is the difference between before triggers and after triggers?
- Explain all Trigger context variables (isInsert, isUpdate, isDelete, isUndelete, isBefore, isAfter, isExecuting, size, operationType).
- What is the difference between Trigger.new and Trigger.old?
- In which trigger events are Trigger.new and Trigger.newMap available?
- In which trigger events are Trigger.old and Trigger.oldMap available?