Programmatically retrieve list of sandbox IDs linked to a production org

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.


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.

Tags:

Sandbox

Apex