Getting Instance Name of org with a domain

A SOQL Query on the Organization object will provide you with your org's InstanceName, regardless of whether you're using My Domain or not:

String instanceName = [select InstanceName from Organization limit 1].InstanceName;

--> NA31, CS9, etc.

Note, ensure that you run this query in a without sharing annotated class, otherwise the query will only be visible to System Administrators.


Go to http://trust.salesforce.com/trust/status/# and click 'What instance am I using?'. It will show your instance name.

There have been reports that the domain lookup doesn't work all the time. If that is the case you can do a CNAME Lookup on your domain instead it will return something like this:

;; ANSWER SECTION: custom-domain-dev-ed.my.salesforce.com. 300 IN CNAME na17.my.salesforce.com.


You can add your org to an Environment Hub and it will display you the instance on which the org is located. To get more infos about Environment Hub (it can do a lot of other useful things for you!), check this out: https://help.salesforce.com/HTViewHelpDoc?id=environment_hub_main.htm

enter image description here