I embeded an url in email template, like this:


Sometime the account name would contain a blank, such as Allen li. Then we will get an url like this: http://www.abc.com?param1=Allen li

That's a problem because the link will be divided. I don't want fix this by apex code. Is there a solution about this?

  • 1
    Have you tried using the SUBSTITUTE expression and replace ' ' whitespace with %20 which is URL encoded value for whitespace? – Boris Bachovski Mar 24 '14 at 3:37
  • We can't use formula function in email template. – Allen Li Mar 24 '14 at 10:34

You can use the URLENCODE formula function.

Encodes text and merge field values for use in URLs by replacing characters that are illegal in URLs, such as blank spaces, with the code that represent those characters as defined in RFC 3986, Uniform Resource Identifier (URI): Generic Syntax. For example, blank spaces are replaced with %20, and exclamation points are replaced with %21.

{!URLENCODE(text)} and replace text with the merge field or text string that you want to encode.

i've just tested this with a Text based Email Template and it seems to work just fine. The following...



| improve this answer | |
  • Your welcome, go Visualforce functions! :-) – Andrew Fawcett Apr 3 '14 at 6:58

You can create formula field where you will replace all unwanted characters and build link

| improve this answer | |

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.