Development questions
How do you do conditional rendering and list iteration in LWC templates?
DevelopmentEasy
Conditional rendering
html
<template lwc:if={isLoading}>Loading…</template>
<template lwc:elseif={hasError}>Error</template>
<template lwc:else>Content</template>
(The older if:true / if:false directives still work but lwc:if, lwc:elseif, lwc:else are the current recommendation.)
Iteration
html
<template for:each={contacts} for:item="c">
<li key={c.Id}>{c.Name}</li>
</template>
Also iterator:it={contacts} when you need it.first / it.last.
Rules: every iterated top-level element needs a unique, stable key (not the index), and templates only accept simple property references, so compute logic in JS getters.
lwctemplatesconditional
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?