How to get Sandbox name using Apex?

How to get Sandbox name using Apex?

When a Salesforce Sandbox is created or refreshed, the username will be appended with the Sandbox Name. So, we can use UserInfo.getUserName() and find the sandbox name from the User’s Username value.

Sample Code:

UserInfo.getUserName().substringAfterLast('.').toUpperCase();

Leave a Reply