Getting Salesforce Organization Server Url

Tuesday, February 23, 2010 by Aslam - The Alexendra
Hi All,
Recently i faced a situation where i need to get Current Org Server URL (Host Url) in Trigger. I know we can get it easily in VF or Apex Class, but what about in Trigger or some future method? One of my colleague Mr. Yogesh Rankawat suggested me a very good way to do this easily (Thanks to him). So here i am going to tell you this method.

1) Create a simple class with following code:-
public class HostUrl{
public string url {get;set;}
public HostUrl(){
url = ApexPages.currentPage().getHeaders().get('Host');
}
}


2) Create a even simple VF page with following code:-
<apex:page sidebar="false" showHeader="false" controller="HostUrl" contentType="text">{!url}</apex:page>

3) Now just simply use below code to get the Server URL

PageReference pg = Page.HostUrl;
String SERVER_URL = pg.getContent().toString();

Isn't it too simple!!! If you know even better way, then please share.

Thanks
Aslam Bari
Posted in | 2 Comments »

Latest From My Blogs

Tuesday, February 16, 2010 by Aslam - The Alexendra
Hi Friends,
Here are my some latest blogs on my projects related to Salesforce:-

1. Salesforce Pinger
Link

2. Salesforce Bot
Link

Thanks
Posted in | 0 Comments »