i create lwc component, i select body from email template. i have error: null body.

public with sharing class SendInvoiceService {
    public static List getPreview(id contentVId){
        return [SELECT Id, Title, FileExtension, ContentDocumentId From ContentVersion where id=:contentVId];
    public static SendInvoice__c getInvoice(id oppId) {
        Opportunity opp=[select id,Invoice_number__c,
                         (select IsPrimary,Contact.Email,Contact.AccountId,Contact.FirstName,Contact.LastName
                          from OpportunityContactRoles where IsPrimary=true) 
                         from Opportunity where id=:oppId];
        OpportunityContactRole oppCR=opp.OpportunityContactRoles;
        SendInvoice__c invoice=new SendInvoice__c();
        invoice.Body__c=[select body from EmailTemplate where name='OpportunityAndr'].body+' body';
        return invoice;


<lightning-card title="Send Invoice" >
<lightning-input label="EmailBody" value={realFormData.Body__c} if:true={realFormData} data-field="Subject"></lightning-input>


import { LightningElement, api, wire } from 'lwc';
import getInvoice from '@salesforce/apex/SendInvoiceService.getInvoice';
import BODY_FIELD from '@salesforce/schema/SendInvoice__c.Body__c';
import { getSObjectValue } from '@salesforce/apex';
import { refreshApex } from '@salesforce/apex';

export default class sendInvoiceLWC extends NavigationMixin(LightningElement) {
@api recordId;
@api wiredContact;
@api realFormData;
@api InvoiceObj;
@wire(getInvoice, { oppId:'$recordId' }) fetchedInvoice( resp){
    this.wiredContact = resp;
    this.realFormData = this.wiredContact.data;

get Subject() {
    return this.InvoiceObj.data?getSObjectValue(this.InvoiceObj.data, BODY_FIELD):'nothing';

my error enter image description here

my email body enter image description here

  • what happens if you do that query in the dev console?
    – Nick Cook
    Feb 7 at 22:32

1 Answer 1


A likely reason for this is that you have an HTML (html or custom) email template and the "body" may only be saved in field HTMLValue

execute this query and you'll see:

select id, name, body, htmlvalue, templateType from emailTemplate 

Your Answer

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