Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieve salesforce instance URL 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:

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.

From the Apex controller:

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

and

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 what I want: https://cs1.salesforce.com?

like image 569
Jan Julian Avatar asked Feb 20 '12 22:02

Jan Julian


1 Answers

Here's something that I used within my Apex Trigger

System.URL.getSalesforceBaseUrl().getHost().remove('-api' );

This gives me proper URL

like image 104
Shivanath D Avatar answered Oct 02 '22 10:10

Shivanath D