Find your content:

Search form

You are here

serverurl and visualforce


How do I get the server URL from a visual force page?

I am using conga and when I invoke from a button the code it passes the server URL as:


When I use {!$Action.Partner_Server_URL_210} I get:

ServerUrl=https%3A%2F%2F******%2Fservices ....

How do I get the actual server URL ?

Can I go ahead and hard code the URL ? Is there any time the Prod server URL would change?

Please let me know!!!

Update : Though I was able to get the params the serverURL and the sessionID in multiple ways,finally I ended up taking a different route I went over conga documentation and ended up taking approach 3 from the conga support page: (Thanks to Andrew)

Different approaches I tried : Approach 1: (FAILED) 1) Session Id and Server URL code was

<a href=" 
&DS7=3" />

2) (FAILED) Controller:

string href_string{get;set;}
***string sessionid = userinfo.getsessionID();
string serverurl = URL.getSalesforceBaseUrl().toExternalForm();***
href_string = ''+ '\n'+
'SessionId='+sessionid + '\n'+ 
'&ServerUrl='+serverurl+ '\n'+ 
'&Id='+{!someaccountId}+ '\n'+ 
'&TemplateId='+something_id+ '\n'+
'&FP0=1'+ '\n'+ 

Approach 3 : (PASSED)

<apex:commandButton value="Create PDF Quote"
<Script Language="JavaScript">
function openConga() {'{!URLFOR($Action.Account.Conga_Composer_temp,Account_Id)}', '','scrollbars=yes,menubar=no,height=800,width=700,resizable=yes, toolbar=no,location=no,status=yes'); }

controller :

public string Account_Id{get;set;}

Account_id = 'query accounts get accountid based on picklist name/Id combination';

I was able to get it done but the grudge of not having found what went wrong with the apexy approach will always remain :(

URL that the button and VF generated were the same except for the session ID ( I doubt that could be the culprit,because the session Id if invalid the page would fail to load ): HERE IS THE COMPARE IT SCRESHOT :

Thanks to all who helped me solve this issue !!!

enter image description here

Attribution to: Rao

Possible Suggestion/Solution #1

Yes, it's possible that your organizations instance could be changed between 2 pods. I've been using one that's moved before.

For example:


SFDC Organizations are portable between pods. They should give you some warning, but it's good just to be safe.

Generally it would be better idea to use Javascript on the client-side, or on the server side, the APEX PageReference class to determine the current URL your code is executing on. Documentation of page-reference class.


PageReference pageRef = ApexPages.currentPage();
Map<String,String> headers = new Map<String,String>();
headers = pageRef.getHeaders(); // returns a map
string host = headers.get('Host');

I believe this is how you get the hostname into a string!

Attribution to: jordan.baucke

Possible Suggestion/Solution #2

Here is a link to what Conga Support recommends. Recomended approach 2 is what your asking about regarding the Partner_Server_URL and in my view better than approach 1 they describe.

So what you tried in your question should actually work, {!$Action.Partner_Server_URL_210} returns a Visualforce domain in a VF page contect, which does look odd, however you can actually use these domains for API calls. I've come across this when using URL.getSalesforceBaseUrl to call the Metadata API.

From Apex another approach is to use the (relatively new) method on the URL.




If the variant of the Salesforce base URL returned by the above in Visualforce contexts does not work for you. You can try this formula. However be warned it assumes that Salesforce will continue to utilise the format. But for now it works!

{!SUBSTITUTE(SUBSTITUTE(LEFT($Api.Partner_Server_URL_210, FIND( '/services', $Api.Partner_Server_URL_260)), 'visual.force', 'salesforce'), 'c.', '')}

I would still be inclined to ask Conga Support why there advice is not working for you though. ;-)

Attribution to: Andrew Fawcett
This content is remixed from stackoverflow or stackexchange. Please visit

My Block Status

My Block Content