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
hemmhemm 

Get Salesforce Server via Apex

I have tried many different approaches, but no approach has worked successfully.  Can anyone prove out a way to obtain the Salesforce server an org is running on via Apex code? There will be no UI interaction. This will need to run purely as an Apex script to obtain the answer (e.g. "na1", "emea", "cs1")

TehNrdTehNrd

I know of no way. This is a known gap in the platform. It has been discussesd extensivley here: http://community.salesforce.com/t5/Apex-Code-Development/How-to-get-server-URL-in-Apex/td-p/83770

 

And here is an idea: Apex method to identify salesforce.com server 

 

What some people have done is create a Setup page where the end user can enter this value and then it is saved to a custom setting.

Novo_ArtisNovo_Artis

If you really want to automate it you could make a SOAP login request using the HTTP class to your own instance (within the response is a string describing the server address)
Still not all that smooth considering you would need to give it a valid user/password to use...