function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SanchSanch 

Accessing Server URL in the controller

Hi there,

 

I have a visualforce page which has a link that will taken in the server URL to an application outside of salesforce.  I am trying to access the Server URL on the visual force page controller. But I can't seem to use the $Api.Partner_Server_URL_180 in the controller. Why is that? How do I access the Server URL from the controller? Please let me know. I would really appreciate everyone's help. Thank you.

SanchSanch

Hi there,

I am trying to get the server url for the visualforce page controller. I was able to archieve this through the sample that I found here: http://blog.sforce.com/sforce/2009/01/accessing-session-id-and-api-server-url-parameters-with-visualforce.html

 

The serverURL that I am getting through that method is: https://cent.na7.visual.force.com/services/Soap/u/18.0/00DA0000000I1Fa

 

I have a button on the contact page layout and I am also getting the serverURL there as well. But there, I am getting the following as the serverURL: https://na7.salesforce.com/services/Soap/u/18.0/00DA0000000I1Fa

 

why is it different for both? How can I get the URL that I get from the button for the visualforce page controller? Please help. Thank You.

blombardisblombardis

You can do this from the controller

 

 

    public static String getDomain () {

        String hostname = ApexPages.currentPage();
        
        return domain;
        
    }

 

Another example is if you want to get hostname:

 

 

public static String getDomain () {

        String hostname = ApexPages.currentPage().getHeaders().get('Host');
      
        return hostname;
        
    }

 

Maybe some of this code helps you,

Bruno