SOLVED

Re: Best way to display a URL field from an Opportunity in an email?

Subscribe
Go to solution
EllenSchwier
Level 5

Best way to display a URL field from an Opportunity in an email?

I have an email where I need to display a URL that is stored in a field on the Opportunity. I successfully wrote a Velocity script that populates a token with this field from the most recent active opportunity. However, I am running into the same problem that this post discusses. Because the field is a URL, the email script is not always compiling. I was seeing the issue in about 50% of clicks, that the link actually shows as the script itself. At first I wanted to solve it by transferring the field from the opportunity to the person whenever the field was updated. But that did not work

 

Summary:  I am pulling a URL from an opportunity using a script token. I use it in an email link like this: https://{{my.scripttoken}}. Tracking the link breaks how this URL is shown in the actual email. Any suggestions?

1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Best way to display a URL field from an Opportunity in an email?

That article is almost completely incorrect and should be removed. I’ll work on that.

 

The actual (and only) problem with links in Velocity is when you reference the same Velocity variable in multiple URLs, expecting it to have different values. That doesn’t work, I have a whole blog post about the crazy thing you need to do to solve it.

 

But if you’re only outputting a single URL, then simply ensure you output the entire <a> tag from Velocity. That means the opening <a> through closing </a> and everything in-between.

 

Then insert the {{my.token}} in the appropriate location in the email. Don’t do https://{{my.token}}  when the {{my.token}} is a Velocity token.

View solution in original post

7 REPLIES 7
SanfordWhiteman
Level 10 - Community Moderator

Re: Best way to display a URL field from an Opportunity in an email?

That article is almost completely incorrect and should be removed. I’ll work on that.

 

The actual (and only) problem with links in Velocity is when you reference the same Velocity variable in multiple URLs, expecting it to have different values. That doesn’t work, I have a whole blog post about the crazy thing you need to do to solve it.

 

But if you’re only outputting a single URL, then simply ensure you output the entire <a> tag from Velocity. That means the opening <a> through closing </a> and everything in-between.

 

Then insert the {{my.token}} in the appropriate location in the email. Don’t do https://{{my.token}}  when the {{my.token}} is a Velocity token.

EllenSchwier
Level 5

Re: Best way to display a URL field from an Opportunity in an email?

Thank you for this! I was able to use this to update my script and it now appears to work.

EllenSchwier
Level 5

Re: Best way to display a URL field from an Opportunity in an email?

#set( $defaultLink = "www.example.com/" )
#foreach( $opportunity in $OpportunityList )
#if( $opportunity.salesStage.equals("Active") )
#set( $OutputURL = $opportunity.Opportunity-URL-value )
#break
#end
#end
#set( $OutputURL = $display.alt($OutputURL, $defaultLink) )
<a href="https://${OutputURL}">Click here</a>

 

I thought I had this working but it is broken again. @SanfordWhiteman do you mind doing a double-check of this from a Velocity script perspective?

 

The current output people are getting is "https://${OutputURL}" rather than the actual URL.

SanfordWhiteman
Level 10 - Community Moderator

Re: Best way to display a URL field from an Opportunity in an email?

Are you testing with a real email, not a sample? Also, you only have the {{my.token}} once in the email, right?

 

The code itself looks OK to me at a glance.

EllenSchwier
Level 5

Re: Best way to display a URL field from an Opportunity in an email?

@SanfordWhiteman Thank you so much for taking the time to review. Yes, I am testing with real emails, and yes, the token is only used once. 

 

When I include the lines for the default link, everyone seems to get the default link. When I remove those, the link comes in with the token instead of the actual link. I am still experimenting, but not sure where it is going wonky.

EllenSchwier
Level 5

Re: Best way to display a URL field from an Opportunity in an email?

Just to follow up on this, it turns out the capitalization in API names was different between sandbox and production, which is why I was having issues. The code was perfect. Thank you again for the review!

SanfordWhiteman
Level 10 - Community Moderator

Re: Best way to display a URL field from an Opportunity in an email?

That’ll trip you up...