DomainCreator Class

Use the DomainCreator class to return a hostname specific to the org. For example, get the org’s Visualforce hostname. Values are returned as a hostname, such as MyDomainName.lightning.force.com.

Namespace

System

Examples

This example code fetches the org’s My Domain login hostname and the Visualforce hostname for the uat package.

//Get the My Domain login hostname
String myDomainHostname = DomainCreator.getOrgMyDomainHostname();

//Get the Visualforce hostname
String vfHostname = DomainCreator.getVisualforceHostname('uat');

In this case, in a production org with a My Domain name of mycompany, myDomainHostname returns mycompany.my.salesforce.com. And in the same production org, vfHostname returns mycompany--uat.vf.force.com.

This example code creates a link to a Salesforce Account record. It gets the Lightning hostname associated with this org. It then gets the Account record ID and uses concatenation to build the link URL.
//Get the org’s Lightning hostname
String myLightningHostname = DomainCreator.getLightningHostname();
 
//Get the ID of a record Account with the name ‘Acme’
Account acct = [SELECT Id FROM Account WHERE Name = 'Acme' LIMIT 1];
 
//Build the URL to view the account record
String fullRecordURL = 'https://' + myLightningHostname + '/lightning/r/Account/' + acct.Id + '/view';

DomainCreator Methods

The following are methods for DomainCreator.

getContentHostname()

Returns the hostname for content stored in the org, such as files.

Signature

public static String getContentHostname()

Return Value

Type: String

getExperienceCloudSitesBuilderHostname()

Returns the hostname to access Experience Builder for the org’s Experience Cloud sites.

Signature

public static String getExperienceCloudSitesBuilderHostname()

Return Value

Type: String

getExperienceCloudSitesHostname()

Returns the system-managed hostname for the org’s Experience Cloud sites, such as ExperienceCloudSitesSubdomainName.force.com. If Digital Experiences aren’t enabled, this method throws an InvalidParameterValueException.

Signature

public static String getExperienceCloudSitesHostname()

Return Value

Type: String

getExperienceCloudSitesLivePreviewHostname()

Returns the hostname to access Experience Builder Live Preview for the org’s Experience Cloud sites.

Signature

public static String getExperienceCloudSitesLivePreviewHostname()

Return Value

Type: String

getExperienceCloudSitesPreviewHostname()

Returns the hostname to access Experience Builder Preview for the org’s Experience Cloud sites.

Signature

public static String getExperienceCloudSitesPreviewHostname()

Return Value

Type: String

getLightningContainerComponentHostname(packageName)

Returns the hostname for the org’s Lightning Container Components.

Signature

public static String getLightningContainerComponentHostname(String packageName)

Parameters

packageName
Type: String
The package name for this component.

If packageName is null, this method uses the org’s namespace prefix as the package name. Otherwise, it uses the default namespace.

Return Value

Type: String

getLightningHostname()

Returns the hostname for the org’s Lightning pages.

Signature

public static String getLightningHostname()

Return Value

Type: String

getOrgMyDomainHostname()

Returns the hostname for the org’s My Domain login domain.

Signature

public static String getOrgMyDomainHostname()

Return Value

Type: String

getSalesforceSitesHostname()

Returns the hostname for the org’s Salesforce Sites. If Salesforce Sites aren’t enabled, this method throws an InvalidParameterValueException.

Signature

public static String getSalesforceSitesHostname()

Return Value

Type: String

getSetupHostname()

Returns the hostname for the org’s setup domain, which hosts Setup pages in Salesforce.

Signature

public static String getSetupHostname()

Return Value

Type: String

getVisualforceHostname(packageName)

Returns the hostname for the org’s Visualforce pages.

Signature

public static String getVisualforceHostname(String packageName)

Parameters

packageName
Type: String
The package name for this component.

If packageName is null, this method uses the org’s namespace prefix as the package name. Otherwise, it uses the default namespace.

Return Value

Type: String