function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
kladizkovkladizkov 

Using 1 email template instead of 64 different ones?

Hi,

 

I need to set a workflow in salesforce to send email alert. But, email body has to differ according to values in contacts. Basically, I need to substitute certains values based on conditions in contacts ( its not direct substitutions like {!Contact.FirstName} ). It will be based on conditions in values stored in contacts. For example, if {!Contact.AField} == "atypicalvalue" then substitute "something" else substitute "some other value".When I analyzed, there will be 64 possible types of emails. But, making 64 email templates doesn't look logical.

 

Is there any easy method to do it?

 

Please help!

 

 

SteveBowerSteveBower

Can you change your template to use {!Contact.template_field1} and {!Contact.template_field2}, etc.  (which aren't visible to the users through page layouts) and then use formulas to set the values in those fields?   If it's too complicated to capture the 64 cases in formulas, perhaps use Apex trigger code to set the values.

Best, Steve.

aalbertaalbert

Another option would be to use a Visualforce email template

 

Brian12345Brian12345

I am using one visualforce e-mail template to dynamically display different content based on multiple fields in several objects.  You can use the "rendered" attribute to accomplish this quite nicely.  In the example below, I render the entire panel, which contains two links, based on the criteria in red.  I specifically render the "get teaser" link based upon the criteria in blue.

 

<tr> 
<td colspan="3" style="font-size:10px;font-weight:bold;width:100%;text-align:center"> 
<center><apex:panelGrid rendered="{!IF(or(cx.match_criteria__r.searcher__r.Free_Deal_Report_User__c=True,cx.match_criteria__r.searcher__r.Managed_User__c=True),False,True)}" style="text-align:center" border="0" columns="2"> 
<apex:outputLink style="text-decoration:none" value="https://cathedralpartners.secure.force.com/apex/customerlogin?startUrl=/apex/currentMatch?matchid={!cx.Id}"><center>Go To Deal</center></apex:outputLink> 
<apex:outputLink style="text-decoration:none" rendered="{!IF(cx.Deal__r.Teaser_Attach_Id__c =null,False,True)}" value="https://cathedralpartners.secure.force.com/apex/customerlogin?startUrl=/servlet/servlet.FileDownload?file={!cx.Deal__r.Teaser_Attach_Id__c}"><center>&nbsp;&nbsp;|&nbsp;&nbsp;Get Teaser </center></apex:outputLink> 
</apex:panelGrid></center> 
</td> 

</tr>  

 

 Hope this helps!