Showing posts with label organization. Show all posts
Showing posts with label organization. Show all posts
Saturday, February 4, 2017
Getting Salesforce Organization Server Url
Getting Salesforce Organization Server Url
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();
Isnt it too simple!!! If you know even better way, then please share.
Thanks
Aslam Bari
Available link for download
Labels:
getting,
organization,
salesforce,
server,
url
Subscribe to:
Posts (Atom)