SOLVED

Re: Custom Token - Link to Salesforce Lead

Go to solution
nandoZ
Level 1

Custom Token - Link to Salesforce Lead

Hello! When a lead is submitted via our embedded form on our website, we have an email that gets sent to the assigned Sales Person. In this email, I want to include a link to the lead in SF in the email that gets sent. 

This requires me to pull a sub-string out of the SFDC Standard Field: Photo URL which usually looks like this:
/services/images/photo/00Q3u00001g#######
("/services/images/photo/" is always there, and the length of the string below is always the same)

I need to pull out this part: 00Q3u00001g#######


Then insert that in to here:
SalesForceLink.com/lightning/r/Lead/00Q3u00001g#######/view

I have not done much coding in Marketo, but from the bits and pieces I have found on the internet, I feel like this should
be possible, but I'm not totally sure. Any and all help is appreciated(:

P.S. in a perfect world, I could take the final SF link and have it be a Hyper link to something like "Click here to see lead in SalesForce" but I will take just pasting the link in the email


Edit: I just realized the Field "SFDC ID" field has the string I need, so we can ignore all of that substring shenanigans.

Edit 2: So I did not realize that I could just drop the SFDC ID Token in to a hyperlink, and it just works. So if you are like me and tried to make some convoluted mess, all I did was Insert a link on the phrase "Link to Lead in SFDC" and in the URL section, I have "salesforce.com/lightning/r/Lead/{{lead.SFDC  Id}}/view" and it works perfectly!


1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Custom Token - Link to Salesforce Lead


Edit: I just realized the Field "SFDC ID" field has the string I need, so we can ignore all of that substring shenanigans.

Edit 2: So I did not realize that I could just drop the SFDC ID Token in to a hyperlink, and it just works. So if you are like me and tried to make some convoluted mess, all I did was Insert a link on the phrase "Link to Lead in SFDC" and in the URL section, I have "salesforce.com/lightning/r/Lead/{{lead.SFDC  Id}}/view" and it works perfectly!

Indeed, this is true, though bear in mind it works because the SFDC ID never needs URL-encoding (it uses ASCII numbers and letters). This doesn’t necessarily work for any old field.

View solution in original post

3 REPLIES 3
SanfordWhiteman
Level 10 - Community Moderator

Re: Custom Token - Link to Salesforce Lead


Edit: I just realized the Field "SFDC ID" field has the string I need, so we can ignore all of that substring shenanigans.

Edit 2: So I did not realize that I could just drop the SFDC ID Token in to a hyperlink, and it just works. So if you are like me and tried to make some convoluted mess, all I did was Insert a link on the phrase "Link to Lead in SFDC" and in the URL section, I have "salesforce.com/lightning/r/Lead/{{lead.SFDC  Id}}/view" and it works perfectly!

Indeed, this is true, though bear in mind it works because the SFDC ID never needs URL-encoding (it uses ASCII numbers and letters). This doesn’t necessarily work for any old field.

nandoZ
Level 1

Re: Custom Token - Link to Salesforce Lead

“URL-encoding (it uses ASCII numbers and letters).“

 

This might be a stupid question, but could you expand on this? I’m curious, I’m new to Marketo and am really trying to ramp up my knowledge. 

SanfordWhiteman
Level 10 - Community Moderator

Re: Custom Token - Link to Salesforce Lead

This is less a Marketo thing than a general reality about URLs (which I think all technical marketers need to understand so they don’t create broken links).

 

You can’t use just any character in a URL. URLs are by definition ASCII-only, meaning they can only include the small list of printable ASCII characters. All other characters need to be percent-encoded (a.k.a. URL-encoded/URI-encoded). Furthermore, if you’re trying to include a piece within a single query parameter, it can’t include any characters that would otherwise break the parameter into 2.

 

For example, you can’t include a literal & in a query param value, as the & represents the separator between parameters; it must appear as %26.

 

Another example is the + character, which is special to some servers, and not others — it represents a space, rather than a literal plus sign, on servers that use a loose decoding method. So it must be encoded as %2B. A hash sign/number sign, if meant literally, must be encoded as %23.

 

Marketo doesn’t guarantee that outputting a {{lead.token}} will conform to these requirements, and as fields support the full Unicode range, it’s easy to create a {{lead.token}} that isn’t valid in a URL. Most commonly it’s because of including a plus sign, hash sign, or ampersand, but weirder things happen as well.

 

To ensure a field is properly encoded you must pass it through $esc.url in Velocity. However, it’s possible that because of hard business rules, you know in advance that a field is safe to include as it would look the same after encoding. An example is a Number/Integer field — numbers are all ASCII. Another is an SFDC ID, as that’s known to be only ASCII numbers and letters. But freeform values are not inherently safe.

 

I’ve written many blog posts on these matters. You can start with these: