Domain Class

Represents an existing domain hosted by Salesforce that serves the org or its content. Contains methods to obtain information about these domains, such as the domain type, My Domain name, and sandbox name.

System

Use the Domain class to obtain information about the domains that Salesforce hosts for your org. This class only applies to domains hosted by Salesforce, and can’t be used to generate a new domain.

This code uses the System.DomainParser class to parse a hostname. It then gets the associated domain type.

The following are methods for Domain.

  • getDomainType()

    Returns the domain’s type, such as CONTENT_DOMAIN, EXPERIENCE_CLOUD_SITES_DOMAIN, or LIGHTNING_DOMAIN.

  • getMyDomainName()

    Returns the domain’s My Domain name.

  • getPackageName()

    For a domain that includes the package name, such as a Lightning Component domain or Visualforce page domain, returns the package name. For a domain that doesn’t contain a package name, this method returns null.

  • getSandboxName()

    For a sandbox org domain, returns the sandbox name. For a production org domain, returns null.

  • getSitesSubdomainName()

    For a system-managed Experience Cloud site domain or Salesforce Site domain, returns the sites subdomain name. If enhanced domains are enabled, this method always returns null. When enhanced domains are enabled, the org’s My Domain name is the subdomain for the system-managed domains for Experience Cloud sites and Salesforce Sites domains.

Returns the domain’s type, such as CONTENT_DOMAIN, EXPERIENCE_CLOUD_SITES_DOMAIN, or LIGHTNING_DOMAIN.

public System.DomainType getDomainType()

Type: System.DomainType

Returns the domain’s My Domain name.

public String getMyDomainName()

Type: String

For a domain that includes the package name, such as a Lightning Component domain or Visualforce page domain, returns the package name. For a domain that doesn’t contain a package name, this method returns null.

public String getPackageName()

Type: String

For a sandbox org domain, returns the sandbox name. For a production org domain, returns null.

public String getSandboxName()

Type: String

For a system-managed Experience Cloud site domain or Salesforce Site domain, returns the sites subdomain name. If enhanced domains are enabled, this method always returns null. When enhanced domains are enabled, the org’s My Domain name is the subdomain for the system-managed domains for Experience Cloud sites and Salesforce Sites domains.

public String getSitesSubdomainName()

Type: String