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.

2 Answers 2


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.

  • 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
    Commented Feb 9, 2021 at 19:56

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.

  • 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
    Commented Oct 29, 2014 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
    Commented Oct 29, 2014 at 21:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .