11 votes
Accepted

Extract all occurences of a substring from a string

This is a simple "regular expression" situation. You can use the following code as a starting point: Pattern p = Pattern.compile('\\{!.+?\\}'); string templateContent = 'hello adrian , this is for {!...
sfdcfox's user avatar
  • 491k
4 votes

Custom object doesn't appear in "Related Entity Type" dropdown for Lightning Email Template

I found the issue and was able to resolve it. Firstly, "Track Activities" should be enabled on the object level. Then navigate to session settings and uncheck the option "Enable secure ...
Shiva Pasumarty's user avatar
4 votes
Accepted

What are merge fields in Apex and why are the called so?

A "merge field" simply means an area (the "field") where output from a function or expression is "merged" into the final output. In other words, the source code is basically a template, and some parts ...
sfdcfox's user avatar
  • 491k
4 votes
Accepted

Using {!User.FirstName} in Email template aiming for User object but return current user

I resolved this issue. From the Email Template Editing page, there is an "Available Merge Fields". From that panel, people can choose whatever merge field for the Email template. Here for my usage, ...
Yifei Pei's user avatar
  • 111
4 votes
Accepted

Remove newline characters from address merge field

Use JSENCODE Encodes text and merge field values for use in JavaScript by inserting escape characters, such as a backslash (), before unsafe JavaScript characters, such as the apostrophe ('). ...
Ratan Paul's user avatar
  • 22.7k
4 votes
Accepted

workflow rule and email alerts firing in user context

Workflow Rules evaluate in System context. Field Updates also update in System context. Email Templates, however, honor the field security of the user, because otherwise users could render templates ...
sfdcfox's user avatar
  • 491k
3 votes
Accepted

Why does Messaging.renderEmailTemplate() return a "Field Custom_Field__c does not exist" even when the field does exists?

I think I found the issue, based on your assert I assume you are trying to get the bank__c info related to Submission__c in the unrendered string. Change 'Dear {!Bank__c}...' to 'Dear {!Submission__c....
Rao's user avatar
  • 16.7k
3 votes
Accepted

Email Template Community test email

After some trying I found that when you test the email template via "Send test and verify merge fields" you cannot test any community merge fields like {!Community_Url}. You need to test "live" in the ...
Andrea Voggenreiter's user avatar
3 votes
Accepted

How to control the fields displayed on Contact merge

Most fields are only displayed if they have a value in them (contact information such as emails and phones are always shown). Fields are made editable only if the user has Edit access to the field and ...
sfdcfox's user avatar
  • 491k
2 votes

What merge field can we use in an email template to get the Instance needed to generate a URL to an internal knowledge article?

There's an ancient "API version substring" hack described for example on https://developer.salesforce.com/forums/?id=906F000000096wuIAA, experiment with it a bit? If it won't work in the email ...
eyescream's user avatar
  • 24.1k
2 votes

Can I add merge fields to the 'setplainTextBody' before I send out email?

You should look at the setTreatBodiesAsTemplate method. Optional. If set to true, the subject, plain text, and HTML text bodies of the email are treated as template data. Example usage: Messaging....
Adrian Larson's user avatar
  • 150k
2 votes
Accepted

Merge field not populating

There are few things you are doing wrong. if you are Using Template, you dont have to manually add htmlBody,subject to the Single Email Message instance. As you are sending a message to contact, you ...
Pranay Jaiswal's user avatar
2 votes

Merging subscriberkeys and records

There is no way to 'merge' subscribers. Every individual Contact with a unqiue Subscriber Key also had system defined attributes which can only be changed by Salesforce Service Team and requires their ...
Rain's user avatar
  • 5,765
2 votes
Accepted

Email Alerts and Merge Fields not working.

There is a checkbox on every custom object definition, "Track Activities". You'll need to ensure that the box is set on VOHLI_Leads__c so that it can be the WhatId of a Task. Your merge fields, ...
David Reed's user avatar
  • 92.8k
2 votes

Custom object doesn't appear in "Related Entity Type" dropdown for Lightning Email Template

I know this is quite old now but for anyone viewing this and the suggestions above dont fix the issue. I fixed this by enabling "Enhanced Email" in setup.
Warren Garton's user avatar
2 votes
Accepted

Rerender Error, with controller extension

Don't use a merge field for your rerender attribute. Just use a literal value. Incorrect: reRender="{!covenanttable}" Correct: reRender="covenanttable" When you use a merge field, the markup then ...
Adrian Larson's user avatar
  • 150k
2 votes

Email Alert Triggered in Scheduled flow has blank merge fields for Custom fields Only

Don't know if anyone is following this one still but I had the same issue with a visualforce email template missing some merge fields values when sending an email alert via an scheduled-triggered flow....
DataDonkey's user avatar
2 votes

How to get the {!$Network.NetworkUrlForUserEmails} in apex code?

Two untested ideas: You can render an email template to a string using renderEmailTemplate() - https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_calls_renderemailtemplate.htm ...
Kevin P's user avatar
  • 7,208
2 votes

How to add merge fields related to User and Community in Lightning Email Template

Based on the doc, To insert merge fields into your Experience Cloud site email templates, From Setup, enter Email Templates in the Quick Find box, and select Classic Email Templates. Next to an ...
Swetha Maddali's user avatar
2 votes

Multiple If Statements for a merge field for a HTML Email Template

Try using this formula - {!IF( AND(NOT(ISBLANK(Case.ICMS_ID__c)), NOT(ISBLANK(Case.Portal_ID__c))), Case.ICMS_ID__c, IF(NOT(ISBLANK(Case.ICMS_ID__c)), Case....
Gaurav Suthar's user avatar
1 vote

Custom object doesn't appear in "Related Entity Type" dropdown for Lightning Email Template

I was missing the "Allow Activities", so I enabled it. I tried everything listed above to get it to show up. Refresh, hard refresh, cache reset. Event switched browsers. Nothing helped, so I ...
SFAaron's user avatar
  • 46
1 vote

Custom object doesn't appear in "Related Entity Type" dropdown for Lightning Email Template

In addition to the above (Enhanced Email on, Allow Activities), I also found that the custom object needed to have a tab created for it before it appeared in the dropdown for related entity.
michael's user avatar
  • 11
1 vote

Custom object doesn't appear in "Related Entity Type" dropdown for Lightning Email Template

I had this issue too and it was definitely related to caching. After realizing I didn't have Allow Activities checked on the object settings page, I couldn't see it even after logging out and back in. ...
runningman's user avatar
1 vote
Accepted

Get data using merge fields in apex

The line number of the error doesn't correlate to your code, but it looks like your issue is probably with if(obj.get(field) != null && obj.get(field) != ''){ You're calling sObject.get() ...
David Reed's user avatar
  • 92.8k
1 vote
Accepted

Lightning Email Templates: Custom Merge Fields

Do you mean reference a custom object's lookup relationship fields? You are definitely able to create Lightning Email Templates for a custom object, however you cannot get a hold of that object's ...
shmuels's user avatar
  • 555
1 vote
Accepted

Validate Merge Fields on a Lightning Email Template in Apex

Use this link to find out the EmailTemplateMergeFields. It will give you all the merge fields possible for an object. At the same time parse text of your emailTemplate body. With two lists created, ...
Sudipta Deb's user avatar
  • 1,261
1 vote
Accepted

How to use merge fields while send emails to contact owners?

I came up with this solution : Contact Cont = [SELECT Id, ownerId, owner.Email, AccountId FROM Contact where name = 'Alan Johnson' LIMIT 1]; EmailTemplate ETemp = [SELECT ID FROM ...
Pragati Jain's user avatar
  • 1,570
1 vote
Accepted

Use logged in user merge fields in visualforce email template

You need the $User global variable: Beest Regards, {!$User.Name}
Adrian Larson's user avatar
  • 150k
1 vote
Accepted

What merge field can we use in an email template to get the Instance needed to generate a URL to an internal knowledge article?

To solve this we created a new Custom Setting called Global Settings with a custom field named SfdcInstanceId and then we reference the field in various locations using {!$Setup.Global_Settings__c....
Jason's user avatar
  • 852
1 vote
Accepted

Using the OR Operator Function in Text Email Templates

Check if that works for you {!IF(Enquiry__c.Destination__c = "Barcelona" || Enquiry__c.Destination__c = "Buenos Aires"), "Yes", "No")} Otherwise, formula will be option which I have mentioned ...
Santanu Boral's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible