2

For my custom button with Content Source = URL I use following formula text to get instance domain:

LEFT($Api.Partner_Server_URL_390, FIND('/services', $Api.Partner_Server_URL_390))

that returns "https://vfirst-dev-ed.my.salesforce.com/"

But when I click the button it navigated me to following URL that is includes necessary part with encoded domain:

https://vfirst-dev-ed.my.salesforce.com/servlet/https%3A%2F%2Fvfirst-dev-ed.my.salesforce.com%2F

Please assist, what I do wrong? How I can just go to domain URL when I click the button?

2
  • From your second link, it seems you are forwarding to the same domain. In this case you don't need instance name, you can use relative path. See this SFSE link salesforce.stackexchange.com/questions/3816/… Commented Feb 20, 2017 at 11:25
  • We need to go to visualforce page with URL that starts with vfirst.eu6.visual.force.com where "vfirst" - namespace of our developer instance. Relative URL will get start as eu6.visual.force.com (with it we get "Page does not exist" error). So we need make some additional manipulations with URL (add namespace) that we can do only if it is absolute. Commented Feb 20, 2017 at 11:33

2 Answers 2

2

Link manipulation doesn't work properly with Content Source as URL, URL type OnClick JavaScript is advised to use for such requirement.

Following works for me:

var baseUrl = "{!LEFT($Api.Partner_Server_URL_390, 
    FIND('/services', $Api.Partner_Server_URL_390))}";

alert("baseUrl: " + baseUrl);

Output:

baseUrl: https://forcetrekker-dev-ed.my.salesforce.com/


Added:

For navigation withing Salesforce, you can use relativeURL with URL as Content Source.

5
  • Thanks for the answer. Are there other ways to not use onclick javascript? Problem is the Lightning Experience does not support onclick javascript buttons but we really need lightning compatibility. Commented Feb 20, 2017 at 10:31
  • Updated answer, did you try using a relative URL? Commented Feb 20, 2017 at 10:35
  • Yes, but so I have another issue. We need to go to visualforce page with URL that starts with vfirst.eu6.visual.force.com where "vfirst" - namespace of our developer instance. Relative URL will get start as eu6.visual.force.com (with it we get "Page does not exist" error). So we need make some additional manipulations with URL (add namespace) that we can do only if it is absolute. Commented Feb 20, 2017 at 11:27
  • Can you not use {!$Page.PageName}? It takes care of namespace as well. Commented Feb 20, 2017 at 11:39
  • Seems button with Content Source as URL does not support $Page. I got error: "Field $Page.vfirst__SearchButtons does not exist". Commented Feb 20, 2017 at 11:57
0

Some might wanna try this too, to get a base URL in JS for Custom Button

var baseURL = '{! URLFOR("[restofurl]" + [anyvariabletoadd]) }';
1
  • You shouldn't be still using var in 2019. Commented Sep 20, 2019 at 1:07

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.