Get the salesforce Host Name, Returns the host name of the current URL.
Solution: 1
salesforce winter 23 release a new class DomainCreator. It has the getOrgMyDomainHostname method to get host name.String baseURL = DomainCreator.getOrgMyDomainHostname();
System.debug('Base URL: ' + baseURL );
to get lightning page host name
String lightningHostName = DomainCreator.getLightningHostname();
System.debug(lightningHostName);//resourceful-shark-haq2ar-dev-ed.trailblaze.lightning.force.com
Solution: 2
String baseURL = URL.getSalesforceBaseUrl().getHost();
System.debug('Base URL: ' + baseURL );
Source:
https://developer.salesforce.com/docs/atlas.en-us.240.0.apexref.meta/apexref/apex_class_System_DomainCreator.htm#apex_System_DomainCreator_methods