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
Nathan ANathan A 

Getting the URL for the current organization instance at runtime.

I'm having a problem surrounding the use of:

 

 

ApexPages.currentPage().getHeaders().get('Host');

 

Wherein I'm making that call inside a Trigger deployed by my package on a Custom Object that's also inside my package, and when that resolves at runtime on the client's instance it still returns my developer's account URL rather than the client's instance URL.  Which makes about no sense at all.

 

How do I detect the URL of the instance that's actually running the code, rather than the URL of the instance where the code was developed originally?

SurekaSureka
Hi, Try this, PageReference currentpage = ApexPages.currentPage(); String orgURL = currentpage.getUrl(); Thanks
Pradeep_NavatarPradeep_Navatar

Original structure of Saleforce URL is https://[instance].salesforce.com/[object]/o

 

Try the following code to get the instance name from this line :

 

       //  To Get the current page url.

       PageReference currentpageurl = ApexPages.currentPage();

       String orgURL = currentpageurl.getUrl();

 

        //   Using the split method we will get Instance name.

        orgURL = orgURL.split(‘.’)[0];

        orgURL = orgURL.split(‘//’)[1];

 

Hope this helps.