3

I am designing a Visualforce email template for an approval process and trying to provide a link to Salesforce for the approver. I want to avoid hardcoding of the URL to avoid a post deployment step :)

<apex:outputLink value="https://cs21.salesforce.com/{!relatedto.Id}">Link</apex:outputLink>

The following tag doesn't compile and shows up

Syntax error. Missing '}'

<apex:outputLink value="{!URL.getSalesforceBaseURL().toExternalForm() + '/' +{!relatedto.Id}">Link</apex:outputLink>

The following tag compiles successfully but returns a broken link

<apex:outputLink value="!URL.getSalesforceBaseURL().toExternalForm() + '/' +{!relatedto.Id}"></apex:outputLink>

http://%21url.getsalesforcebaseurl%28%29.toexternalform%28%29+++%27/'

Please advise.

0

1 Answer 1

3

URL.getSalesforceBaseURL().toExternalForm() We can use this in Apex class..

But in VF page we need to use $CurrentPage.URL this will return complete url of current page..

Example https://ratan.ap1.visual.force.com/apex/contactcloudPage

SO just remove the /apex/contactcloudPage from url using LEFT

<apex:outputLink value="{!LEFT($CurrentPage.URL,FIND('/',$CurrentPage.URL,9))+relatedto.Id}">Link</apex:outputLink>

FIND('/',$CurrentPage.URL,9))

9 means number of the character from which to start searching from left to right.

FIND('/',$CurrentPage.URL,9)) checks for the first / after 9 character from left to right.. that return the first / position number. So If My url is https://ratan.ap1.visual.force.com/apex/contactcloudPage then it will check for first / after https:// means It will pick the force.com/ this / and return the position no and LEFT will use this position number for substring

https://help.salesforce.com/htviewhelpdoc?err=1&id=customize_functions_a_h.htm&siteLang=en_US

7
  • 1
    I think you can even remove '/' because it cause double // in generated template
    – kurunve
    Commented Jan 13, 2016 at 9:00
  • @kurunve check my updated ans
    – Ratan Paul
    Commented Jan 13, 2016 at 9:01
  • Second one is not working if you send email. as well as third one
    – kurunve
    Commented Jan 13, 2016 at 9:05
  • @kurunve Thanks.. I am not tested with email template..
    – Ratan Paul
    Commented Jan 13, 2016 at 9:06
  • @Bennie 9 means number of the character from which to start searching from left to right. help.salesforce.com/…
    – Ratan Paul
    Commented Jan 13, 2016 at 12:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .