How to get the current sandbox-name programmatically (dynamically) via APEX?

There is now an official solution that is out with the Spring' 22 release.
You can use the new getSandboxName() method:


System.Domain d = System.DomainParser.parse(URL.getOrgDomainUrl());

System.debug(d.getSandboxName());


You can get more information about this new method in the Apex Reference Guide here.
There are also so other new and useful methods like getMyDomainName().

Comments

Popular posts from this blog

Adding a red asterisk to required fields using label in LWC

The Developer Console didn't set the DEVELOPER_LOG trace flag on your user. Having an active trace flag triggers debug logging. You have 1,978 MB of the maximum 1,000 MB of debug logs. Before you can edit trace flags, delete some debug logs.

Salesforce: Serial and Parallel Approval