0

Assume a client app that allows OAUTH login (client flow), such that upon login I can access REST, Tooling, Metadata APIs (etc.) I can get simple org info (id, urls) via an identity call, and I can get the org name by querying the Organization sObject. There are some Tooling API objects (SandboxInfo, SandboxProcess) related to sandbox creation, but the exist only in the prod org. How can I get the sandbox name, assuming I'm logged in and can call any API?

I've seen a number of questions about getting the Sandbox name via Apex (and none with simple answers), but I'm wondering if any of the APIs provide better options. I do not want to rely on hacks such as parsing user names.

Note: As noted above, I am not constrained by running in Apex. I am looking for an API based solution. This is not a duplicate of any of the several 'how do I get sandbox name in Apex' questions on the site.

Jason Clark
  • 11,867
  • 7
  • 59
  • 118
  • The last part of the username perhaps? user@org.sandboxname – Boris Bachovski May 03 '19 at 04:41
  • @BorisBachovski User name parsing is an unreliable hack. It will work for users cloned from prod as part of the sandbox creation/refresh, but not necessarily for users created in the sandbox, as the naming convention is not enforced. I'd like an official, supported method for getting the sandbox name via API (if any such thing exists). – Jason Clark May 03 '19 at 05:05
  • @TusharSharma This is not a duplicate, as I am not constrained by running in Apex, as the question you linked. I'm looking for a solution using any available salesforce API. – Jason Clark May 03 '19 at 05:14
  • 1
    @JasonClark There's an InstanceName property on the Organization SOAP API, does that help? – Jayant Das May 03 '19 at 12:22
  • @JayantDas Sadly no, InstanceName returns the pod, e.g. NA91 or CS13. – Jason Clark May 03 '19 at 18:23
  • 1
    @JasonClark Oh. I thought it would return the sandbox name. I will see if there's a way to find this out using API – Jayant Das May 03 '19 at 18:24
  • Would those who voted to close as duplicate kindly explain how API calls are the same as Apex? Just because it's not currently possible either way does not make this a duplicate question. – Jason Clark May 03 '19 at 18:24
  • @JasonClark if there doesn't exist an API, then you can actually utilize the Apex way and expose that as a custom API, I think that approach should work too. – Jayant Das May 03 '19 at 18:25
  • @JayantDas I could, if there was a reliable way to do this in Apex. As I stated in the question, i cannot rely on hacks/tricks. For example, the linked question's answers suggest screen scraping (prone to break) and a post-sandbox-copy script, which only works if you add code to an org before creating a sandbox. I need a solution that works in ANY sandbox. If no such solution is currently exposed by SF, I can accept that - but there are a lot of APIs, and I'm hoping someone has figured it out. – Jason Clark May 03 '19 at 18:29

0 Answers0