I'm new to lwc salesforce
I have an apex method called from js and then showed in html that take some time because it contain a soql, the method works when I select a combobox value
<lightning-combobox
name="template"
label="Select Template"
value={selectedTemplate}
placeholder="Select Template"
options={filteredTemplates}
onchange={handleTemplateChange}
></lightning-combobox>
and showing the results in html like this these lightning-input need to be shown already so that's why I'm not using conditional template
<lightning-input
label="Objet message"
value={template.Subject}
onchange={handleInputChange}
data-id="emailSubject"
>
</lightning-input>
<lightning-textarea
value={emailTextAreaValue}
onchange={handleInputChange}
data-id="emailTextAreaValue"
>
</lightning-textarea>
this is the js
@track template;
@track attachs = [];
.....
handleTemplateChange(event) {
this.selectedTemplateId = event.detail.value;
getAll({ templateId: event.detail.value })
.then((data) => {
this.template = data.emailTemplate;
this.attachs = data.attachments.map((item) => ({
label: item.ContentDocument.Title,
value: item.Id
}));
this.emailTextAreaValue = data.renderedEmailTemplateBody;
// Dispatch a custom event to notify parent or other components
const templateChangeEvent = new CustomEvent("templatechange", {
detail: {
templateId: this.selectedTemplateId,
emailTemplate: this.template,
attachments: this.attachs,
renderedEmailTemplateBody: this.emailTextAreaValue
}
});
this.dispatchEvent(templateChangeEvent);
})
.catch((error) => {
console.error("Error fetching template content:", error);
});
}
but when I'm inspecting I'm getting
TypeError: Cannot read properties of undefined (reading 'Subject')