Newer Version Available
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.
Namespace
Usage
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.
Example
This code uses the System.DomainParser class to parse a hostname. It then gets the
associated domain type.
1System.Domain d = DomainParser.parse('mycompany.lightning.force.com');
2String myDomainName = d.getMyDomainName();
3System.DomainType domainType = d.getDomainType();Domain Methods
The following are methods for Domain.
getDomainType()
Returns the domain’s type, such as CONTENT_DOMAIN, EXPERIENCE_CLOUD_SITES_DOMAIN,
or LIGHTNING_DOMAIN.
Signature
public System.DomainType getDomainType()
Return Value
Type: System.DomainType
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.
Signature
public String getPackageName()
Return Value
Type: String
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.
Signature
public String getSitesSubdomainName()
Return Value
Type: String