0

I have created one Lightning application which has form with lightning checkboxes and lightning input. The application has salesOrderId which is field of SBQQ__Quote__c(Quote) object. I have Use Template picklist which fetch's all the email templates based on folder name. when user selects any of the templates it gets the Body & Subject from Email template and display's on the lightning application.

aopsEmailTemplateApp

Now Subject & Body are rendered with merged fields and I need to show data instead of merge fields. So till now I know that we can read entire string and break merge fields and separate object & fields, but I need to get data from Quote object which has lookup to Contact, Account & Opportunity all merge fields used below. Breaking merge fields would only give me Account=>Name not the lookup field name on Quote.

So is it possible to display data from SBQQ__Quote__c(Quote) using Merge fields. Hard part would be to get lookup relationship field names from Quote object with given Merge fields.

1 Answer 1

2

You can use Messaging.renderEmailTemplate to accomplish this task. It accepts a whoId, whatId, and one or more email bodies to render (the parameters are Id, Id, and List<String>, respectively). This operation consumes a SOQL query, but will take care of all the hard work of merging data for you.

9
  • Nice @sfdcfox but I need to pass Account, contact & opportunity id here and we have only WhoId for contact & whatid for Account Feb 5, 2021 at 8:27
  • And in case of Whoid also i need to pass Contact & User Feb 5, 2021 at 8:29
  • @DeepakAgarwal Did you even try this method before dismissing this as useless? Just pass in the Contact and Opportunity and see how well it works.
    – sfdcfox
    Feb 5, 2021 at 11:41
  • i never said its useless where did i ever mention it?? and by the way yes i tried it when i am passing Messaging.renderEmailTemplate(quoLst[0].SBQQ__PrimaryContact__c,quoLst[0].SBQQ__Account__c,new List<String>{emailTempList[0].body}); i am not getting data where account is having merge field Feb 5, 2021 at 12:13
  • Please mind what your saying. Feb 5, 2021 at 12:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .