6

Is there any way to programmatically get a list of sandboxes linked to a production org?

I'd also like to do the reverse: get the ID of the production org corresponding to a sandbox -- but from the answers to "Can the production org id corresponding to a sandbox org id be found via Apex?" it appears that is impossible.

6
+50

You can list sandboxes via Tooling API, by querying the SandboxInfo object.

Select Id, SandboxName from SandboxInfo

You can test this in DeveloperConsole's Query Editor tab by checking the "Use Tooling API" box below the query pane. However, you'll need to call the api endpoint for real code, as this query does not appear to work directly from Apex. The SandboxInfo object is only available in a production org.

1
  • 2
    Awesome, that did it! So simple - why the heck isn't this clearer to find online??? Well, I guess this shows that I need to learn more about the Tooling API... For anyone else who is using SFDX, you need -t in your force:data:soql:query command.
    – DanTheMan
    Feb 9 at 19:56
2

I don't think there is any official method for it. If no one else here tells us better, the only way I can think of to get the information is to use the PageRef.getContent() method on the setup url for the sandboxes and parse the HTML.

2
  • Specifically, the SObject "Sandbox" isn't enabled for access through the API/Apex Code. I tried... Organization[] o = [select id... from organization] (okay!), Sandbox[] s = [Select id... from sandbox] (error: No access to entity: Sandbox).
    – sfdcfox
    Oct 29 '14 at 21:00
  • As an unfortunate there are a lot of points in the setup, which I found only extractable via getContent(). I don't like the approach, because it's possibly unstable in the future and for sure very ugly - but as a last resort better than nothing.
    – Uwe Heim
    Oct 29 '14 at 21:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.