Trying to rewrite an aura component that loads an email template into a rich text field but the field does not update. The tracked value updates as I can see it if I output it.

    label="Select Email Template"
    placeholder="Select Template"
    onchange={changeEmailTemplate} >

<div class="slds-form-element__control">
    <lightning-input-rich-text aura:id="body" value={emailContents.data}></lightning-input-rich-text>


import { LightningElement, api, track, wire } from 'lwc';
import getEmailTemplateContents from '@salesforce/apex/REMOVED_FOR_POST .loadEmailTemplate';
const DELAY = 300;
export default class REMOVED_FOR_POST extends LightningElement {
  @api recordId;

  @track openmodel = false;
  @track emailTemplate = '...';
  @track emailContents;
  @track error;

  @wire(getEmailTemplateContents, {leadID: '$recordId', template: '$emailTemplate'}) emailContents;

  get emailTemplates() {
    return [
    openmodal() {
        this.openmodel = true
    closeModal() {
        this.openmodel = false
    emailResults() {
    changeEmailTemplate(event) {
      const value = event.target.value;
        this.delayTimeout = setTimeout(() => {
            this.emailTemplate = value;
        }, DELAY);


    public static string loadEmailTemplate(Id leadID, String template){

        Lead ld = [SELECT Id, Name, Program_Requested__c, Branch_Parent_Account__r.Name, Branch_Account__r.Type_to_Branch__c, Email, Loan_Officer_Contact__r.Name, Owner.Email, Owner.Phone,Owner.Name, Owner.Title
            FROM Lead
            WHERE Id= :leadID];

        QQ_Email_Template__c et = [SELECT Id, Email_Body__c FROM QQ_Email_Template__c WHERE Name= :template];
        String htmlBody = et.Email_Body__c;

        htmlBody = htmlBody.replace('{{LEAD_LOAN_OFFICER_CONTACT_NAME}}', ld.Loan_Officer_Contact__r.Name);

        htmlBody = htmlBody.replace('{{LEAD_BORROWER_NAME}}', ld.Name);
        htmlBody = htmlBody.replace('{{LEADOWNER_PHONE}}', ld.Owner.Phone);
        htmlBody = htmlBody.replace('{{LEADOWNER_EMAIL}}', ld.Owner.Email);
        htmlBody = htmlBody.replace('{{LEADOWNER_FULLNAME}}', ld.Owner.Name);
        htmlBody = htmlBody.replace('{{LEADOWNER_TITLE}}', ld.Owner.Title);
        return htmlBody;

It works fine until I put it as the value of the lightning-input-rich-text.

  • Could you add the apex controller class you are using ? – Mohith Shrivastava Jun 8 at 20:11
  • 3
    It works, but only after I bring the field into focus by clicking the rich text area. On first change, nothing happens, but if I click inside the rich text area, it will update the data. After that initial click into the field, it updates instantly on dropdown change. – BillyB Jun 9 at 2:23

Can you try to focus the lightning input rich text on change of email template this.template.querySelector('lightning-input-rich-text').focus(); this.template.querySelector('lightning-input-rich-text').blur();

  • Thanks. This worked great. – BillyB Aug 8 at 16:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.