My visualforce email template keeps overwriting my link. The apex:outputLink portion is pulling through a formula field that generates a hyperlink

This is what the formula is:

SUBSTITUTE("https://survey.alchemer.com/s3/6302737/Support-Case-Survey?CaseNumber="&Case__r.CaseNumber&"&ContactId="&Case__r.Contact.Id&"&ContactEmail="&Case__r.Contact.Email&"&AccountId="&Case__r.AccountId&"&ClosedDate="&TEXT(Case__r.ClosedDate)&"&CreateDate="&TEXT(Case__r.CreatedDate)&"&OwnerId="&Case__r.OwnerId&"&Subject="&Case__r.Subject&"&ProductId="&Case__r.ProductId&"&Module__c="&Case__r.Module__r.Case_Safe_ID__c&"&Priority="&TEXT(Case__r.Priority)&"&Type="&TEXT(Case__r.Type)," ","%20")

This is an example link generated by the formula:


For some reason it keeps adding on "https://viewpoint--full--c.documentforce.com/email/" to the beginning of the link when sent. This is what it creates the link to be:


How do we prevent the "viewpoint--full--c..." portion from being added to our link?

<messaging:emailTemplate subject="Please let us know how your Viewpoint Case # {!relatedTo.CaseNumber} was handled!" recipientType="Contact"
    <messaging:htmlEmailBody >
            <p>Dear {!recipient.name},</p>
            <p>Regarding your case “({!relatedTo.Subject})”, please share your experience with Viewpoint support.</p>
            <p>Please click this link to respond: <apex:outputLink value="{!relatedTo.Survey_Link__c}" target="_blank"> Case {!relatedTo.CaseNumber} Survey</apex:outputLink> </p>
            <p>You may reference your case details, including solution, from our Viewpoint Customer Portal at any time.</p>
            <p>Thank you for using Viewpoint Support. We value your business.</p>
            <p>Sincerely, </p>
            <p>Your Viewpoint Support Team</p>
  • What you have right now isn't pulling from any formula field. It's just setting the URL to "www.viewpoint.com". May 12 at 22:06
  • My apologies, I updated it to include the field it is pulling from. The link was a test to see if the forumla field was causing the issue. May 12 at 22:08
  • this is because outputLink is wrapping the merge field with another <a .../> tag
    – cropredy
    May 12 at 22:29

I don't think there's anything wrong with your code. Since the apex:outputLink only creates a simple anchor tag, I'd suggest you just use one of those.

<a href="{!relatedTo.Survey_Link__c}">Case {!relatedTo.CaseNumber} Survey</a>

In the past I've run into issues with apex:outputLink adding odd code to my email templates so I try to avoid them either way. (See for instance this question)

  • I unfortunately got the same error when using the <a> element. I wasn't sure if this is a setting due to the <messaging:emailTemplate or <messaging:htmlEmailBody elements. May 13 at 17:50
  • @KristenSlack That's odd. What happens if you put the link in as just text in the email? Does your formula contain anything else like a hyperlink function or is this the complete formula?
    – Kasper
    May 13 at 21:49
  • If I copy and paste the link directly as text it works correctly, and the formula only contains the link, no extra data. We attempted to change the <a> element to be our company website (ruling out an issue with the field) and received the same error. May 13 at 21:53
  • @KristenSlack Make sure there's no spaces or anything before the html part of the URL. If that isn't the case either, then I'd suggest you try a different sandbox or depending on your organisation perhaps try the same thing in production.
    – Kasper
    May 13 at 21:56

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.