当前位置:网站首页>Resolve merge fields in salesforce
Resolve merge fields in salesforce
2022-07-27 18:08:00 【sf_ wilson】
【 Preface 】: stay Salesforce It is used in Merge Fields A lot of places , Such as Process Builder,Workflow, But the easiest scene to think of is Email Template Use . If you compare carefully Merge Fields Editor , You will find that there are some differences in the linkage between objects and fields , Anyway Its essence is still constructed in the background SOQL, Then based on limited parameter clues ( Such as WhatId or WhoId) Retrieve value . This article will introduce about... With a specific case Merge Fields General solution for parsing , In this process, the technical boundary of the existing scheme is explained , And discuss how to find more generic ways to solve more Merge Fields Scene .
【 Case study 】: If we want to be in Salesforce Build a platform based on the platform , For our platform Business Account(Partner), We want them to maintain their own system email templates , To reduce operation and maintenance costs . such , Whenever the supplier on the platform successfully delivers the project , The system will trigger an email to notify the end customer . The screenshot of basic data is as follows :
WhatId:

Related Record with WhatId:

WhoId:

Email Body of the Custom Email Template Record:

【 General solution 】:
analysis :
Business User Can't be like some privileged Internal User Such a free access Email Template, But they still have the original intention of pursuing their own personalized brand , Like other businesses, they want every email sent to the system to convey the temperature of the brand and show personalized content to customers .
programme :
For this purpose, as a development , We can still Use customization Object structure Email Template To replace the standard Classic Email Template, such Partner Medium Manager We can carefully tailor our initialized system email template like accessing customer information , At the same time, it is convenient for us to be different Partner Template data between . For the placeholder in the template Merge Fields, We will adopt Messaging.renderEmailTemplate Method to get the parsed Body Content .
The implementation of :
public class MergeFieldsBuilder {
public static String renderEmailTemp(Id whoId, Id whatId, List<String> bodies){
// Id of the sObject, list of Email template bodies
List<Messaging.RenderEmailTemplateBodyResult> renderEmailTemplateBodyRes= Messaging.renderEmailTemplate(whoId, whatId, bodies);
return renderEmailTemplateBodyRes[0].getMergedBody();
}
}
EmailTemplate__c et = [SELECT HTMLValue__c, Body__c FROM EmailTemplate__c WHERE Name ='Project_Delivery_Notification' limit 1];
System.debug(LoggingLevel.INFO, '*** et.Body: ' + et.Body__c);
String whoId = '0037F00002DM18Y',
whatId = 'a087F000000l0cD';
String mergedBody = MergeFieldsBuilder.renderEmailTemp(whoId, whatId, new List<String> {et.Body__c});
System.debug(LoggingLevel.INFO, '*** mergedBody: ' + mergedBody);Output results :

【 Technology boundary 】:
In this scheme, we do not build based on the consolidated fields entered by business personnel SOQL, The reason is simple , It is difficult for us to extract Merge Fields Then construct them into Master Main single SOQL sentence , So the customized email template still hasn't come out of the standard Email Template The defects of :
#1. Still need to follow Std Email Template Of Merge Fields Space occupying style . Even if Master Object by Project__c, about Project Of Contact_Email__c Custom fields cannot be removed from the template Contact_Email__c Because it is bound by two clues (WhoId / WhatId);
#2. You cannot cross object reference fields, that is, children and parents . Such as the output result section icon A Region ,Project__c.Account__c.Industry We expect output Education, But it can't be realized ;
#3. Unable to show sub records List Information is the father checks the son . If we want to show Project Sub record multi payment Price Of List Record , Two cannot be Price The record is parsed .
【 Generic scheme 】:
A. In the field of mail template single cause , in the light of #3 The defects of , We usually use Combination method To solve . For example, customization is based on ProjectId download Price list CSV File functionality , Then add the attachment to the email when sending it .
B. For the resolution requirements of both parent and child checking parents in the template , With the help of LWC Of SOQL Builder Build a single SOQL sentence ( At the same time, it includes the child checking the father & Father and son ), Then turn the found records into JSON Format , Combined with third-party tools, you can drag and drop fields when configuring templates Mapping; It is worth mentioning that this method is also applicable to unrelated input clues , Multiple required SOQL To cover free release Merge Fields Application scenarios of , Such as building multiple JSON, For customers to switch JSON Make field Mapping.
The effect is as follows :

边栏推荐
- 美团到餐“祖传数仓”标准化治理笔记
- [MCU] 2.3 CPU of AT89S52
- TCP connection status identification (syn, fin, ACK, PSH, RST, urg)
- 最新大厂高级面试题 必备
- Soul 1: why is es more suitable for complex condition search than MySQL?
- 备份表恢复表
- shell常见命令(1)——变量大小写转换
- VSS tip: search all checked out files (search checked out files according to users)
- [introduction to database system (Wang Shan)] Chapter 4 - Database Security
- 知物由学 | 从0到1搭建实时反外挂机制,多维度补充手游攻防力
猜你喜欢
![[Southwest University] information sharing of postgraduate entrance examination and re examination](/img/15/298ea6f7367741e1e085007c498e51.jpg)
[Southwest University] information sharing of postgraduate entrance examination and re examination

Numpy array matrix operation

JS to realize the right-click menu bar function

Evaluation index of machine learning (II) -- classification evaluation index

TCP的连接状态标识 (SYN, FIN, ACK, PSH, RST, URG)

What should we pay attention to when choosing the LED display screen of the stadium

Knowing things by learning | app slimming down, the way of safety reinforcement under the new generation AAB framework

How difficult the interview is! I was forced to survive the six rounds of interview of ant financial! Almost out (interview resumption)

Establishing SSL connection without server‘s identity verification is not recommended

EF框架简介
随机推荐
[introduction to database system (Wang Shan)] Chapter 1 - Introduction
微信小程序 实现位置地图显示,引入map地图,不含导航
numpy数组矩阵操作
卷积神经网络——从R-CNN,Fast R-CNN到Faster R-CNN,Mask R-CNN
快解析结合华途文档加密软件
Common shell commands (1) -- variable case conversion
Yanrong technology was selected as Beijing's "specialized and innovative" in 2022 to lead hybrid cloud file storage
知物由学 | 从0到1搭建实时反外挂机制,多维度补充手游攻防力
In the first week of June, risk control of e-shield business paid attention to 15 institutions such as New Oriental XRS, which were fined
美团到餐“祖传数仓”标准化治理笔记
Convolutional neural network -- Introduction to FPN (feature pyramid networks)
Soul 1: why is es more suitable for complex condition search than MySQL?
JDBC连接数据库读取前台无法显示数据
卷积神经网络——YOLOV1论文翻译
Layout of flutter
js实现右键菜单栏功能
Cow! His secret is to reproduce the paper in 2 hours——
[introduction to database system (Wang Shan)] Chapter 11 concurrency control
How to learn C language? This article gives you the complete answer
Zhengzhou University database course resource description