Thanks for the quick response :) , the reason I ask is that the subdomain on the Site object in sandboxes doesn't get updated to take into account the sandbox name. For example if the subdomain for a site in production is abc when you query the Subdomain field of the Site record in apex it will return abc. If you setup a sandbox with the name efg. The sandbox name is also a subdomain but there's no way of getting it to regenerate the abc.edf.cs3.force.com url.
Unfortunately, Sandbox related metadata (like Name) is not currently available in Apex of any API.
Thanks for the quick response :) , the reason I ask is that the subdomain on the Site object in sandboxes doesn't get updated to take into account the sandbox name. For example if the subdomain for a site in production is abc when you query the Subdomain field of the Site record in apex it will return abc. If you setup a sandbox with the name efg. The sandbox name is also a subdomain but there's no way of getting it to regenerate the abc.edf.cs3.force.com url.
Interesting use case. Guess you'll need to hardcode the Sandbox sub-domain for now :(
Name of Sandbox: UserInfo.getUserName().substringAfterLast('.com')
You can use the new getSandboxName() method: You can get more information about this new method in the Apex Reference Guide here (https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_System_Domain.htm#apex_System_Domain_getSandboxName).
There are also so other new and useful methods like getMyDomainName().