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?

  • 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/… – Saroj Bera Feb 20 '17 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. – Colombo Feb 20 '17 at 11:33
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.

  • 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. – Colombo Feb 20 '17 at 10:31
  • Updated answer, did you try using a relative URL? – Raul Feb 20 '17 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. – Colombo Feb 20 '17 at 11:27
  • Can you not use {!$Page.PageName}? It takes care of namespace as well. – Raul Feb 20 '17 at 11:39
  • Seems button with Content Source as URL does not support $Page. I got error: "Field $Page.vfirst__SearchButtons does not exist". – Colombo Feb 20 '17 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]) }';
  • You shouldn't be still using var in 2019. – Adrian Larson Sep 20 at 1:07

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.