1

I am creating a html template with a link that includes merge fields as params.

Example:

<a href="http://example.com/?region={!Contact.Region__c}">Click me</a>

I wish to URL encode the merge field so that if spaces are present - for instance if the region is "Asia Pacific" - they are correctly encoded with %20's etc.

I have tried the following but it does not pass any merge field value at all:

<a href="http://example.com/?region={!URLENCODE(Contact.Region__c)}">Click me</a>

Any help much appreciated.

1

Yes unfortunately SFDC email templates do not support inline formulas, nor does the Formula field type support URLENCODE(). The "easiest" way I'm aware of to accomplish this with native SFDC templates is to create a formula field that uses the SUBSTITUTE formula to explicitly replace all the special characters you care about. e.g.

SUBSTITUTE(SUBSTITUTE(my_field__c, ' ', '%20'), 'some other character', 'subbed character')

I think it's also possible, but I'm not certain, that if you auto-populate a URL type field (via trigger or workflow, for instance) it gets auto-encoded.

EDIT: also worth mentioning that you can use Visualforce Email Templates to give you access to more of the formula/templating functionality in Visualforce, but that may be overkill in this case.

0

I am not sure if this is something new or if it was here even back in 2014 when this question was posted, but now you can use the URLENCODE function in email templates and seems to be working ok.

Related answered post can be found here: How to transfer url in email template

This question should ideally be marked as duplicate

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.