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
Jan JulianJan Julian 

Retrieve salesforce instance instead of visualforce instance

From a visualforce page, I need to retrieve our organization's salesforce instance's URL, and not the visual force URL.

 

For example I need https://cs1.salesforce.com instead of https://c.cs1.visual.force.com

 

Here's what I've tried so far and the outcome I got:

 

  1. Accessed the Site global variable from the VF Page .

    <apex:outputText value="{!$Site.Domain}" /> returns null

    Sidenote: Everything in $Site.xxx seems to return null.

  2. From the Apex controller

     public String getSfInstance()
     {
     return ApexPages.currentPage().getHeaders().get('Host');
     }

    public String getSfInstance() { return URL.getSalesforceBaseUrl().toExternalForm(); }

     

    returns c.cs1.visual.force.com and https://c.cs1.visual.force.com, respectively.

     

    Question: How do I retrieve the right instance: https://cs1.salesforce.com?


kiranmutturukiranmutturu

you will the main host name fromt the below try this

 

system.debug(apexpages.currentpage().getheaders().get('X-Salesforce-Forwarded-To'));