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
Sean Connolly 11Sean Connolly 11 

Sandbox instance url


Is there a way to get the instance url for a specific sandbox without being logged into that org? 

I am attempting to assemble a list of Sandbox orgs along with their corresponding instance url's.  The idea being that logging in via test.salesforce.com leaves it up to the user which org they log into.  But if you direct them directly to the instance url, they will connect to the correct org.  As well as catching when an org is refreshed, and directing them to the correct page.  This is for an admin-type application where I have full access to the production org for any queries.

Via the tooling api, I have retrieved a list of SandboxInfo records that give me the active sandboxes.  Using the sandbox names found there, I can get the Org Id from SandboxProcess.  But from there, I'm stuck.  If you go via the UI, Salesforce gives you the option to login to a sandbox from the Setup->Sandboxes page, and it directs you to the correct instance url, so the information is obviously present somewhere.  

Put another way, I have an org id, is there a way via the production org and only using apis to figure out the instance url of the sandbox?

Thanks,
-Sean
 
 
EllEll
I also had a look around but also can't find anywhere the instance URL gets stored - if it is stored on an object it must be hidden, as EnvironmentHubMembers also show instance but don't have it as a field on the object.

The only thing I could think of that you do your side is show the list of sandboxes initially and the first time get them to log in via test.salesforce.com, but as soon as they log in pull the instance info off the Organization object and store it in your application. Then the next time they go to the list of sandboxes it can be the correct URL rather than the generic one.
Sean Connolly 11Sean Connolly 11
That's what I'm currently doing.  It works, but its less than ideal, as people have made mistakes and it's hard (but not impossible) to ensure they've logged into the correct sandbox.  It would be much nicer if we could just have that information available as part of SandboxInfo or similar.
Thanks,
-Sean