DomainParser Class

Use the DomainParser class to parse a domain that Salesforce hosts for the org and extract information about the domain.

Namespace

System

Examples

This example code parses the org���s Lightning domain and gets the My Domain name and domain type from the System.Domain object.

1System.Domain d = DomainParser.parse('mycompany.lightning.force.com');
2String myDomainName = d.getMyDomainName();
3System.DomainType domainType = d.getDomainType();
This example code parses a known Visualforce URL to get the domain type, the org’s My Domain name, and the package name.
1//Parse a known URL
2System.Domain domain = DomainParser.parse('https://mycompany--abcpackage.vf.force.com');
3
4//Get the domain type
5System.DomainType domainType = domain.getDomainType(); // Returns VISUALFORCE_DOMAIN
6
7//Get the org’s My Domain name
8String myDomainName = domain.getMyDomainName(); // Returns mycompany
9
10//Get the package name
11String packageName = domain.getPackageName(); // Returns abcpackage

DomainParser Methods

The following are methods for DomainParser.

parse(hostname)

Parses a passed hostname of a domain that Salesforce hosts for the org, and returns the System.Domain.

Signature

public static System.Domain parse(String hostname)

Parameters

hostname
Type: String
The label that identifies a Salesforce host, including all subdomains but without the protocol, path, or any parameters. For example, mycompany.my.site.com or mycompany--sandbox1.sandbox.my.salesforceforce.com.

If the hostname format is invalid, it isn’t a Salesforce hosted domain, or it isn’t owned by this org, this method throws an InvalidParameterValueException.

Return Value

Type: System.Domain

parse(url)

Parses a passed uniform resource locator (URL) of a domain that Salesforce hosts for the org, and returns the System.Domain.

Signature

public static System.Domain parse(System.Url url)

Parameters

url
Type: System.Url
A uniform resource locator (URL) for a Salesforce org, including all subdomains and the protocol. For example, https://mycompany--sandbox1.sandbox.my.salesforceforce.com.

The URL can also include paths and parameters. For example, https://mycompany.my.site.com/en/us/help or https://mycompany.file.force.com/servlet/servlet.FileDownload?file=015300000000xvU.

If the URL format is invalid, it isn’t a Salesforce hosted domain, or it isn’t owned by this org, this method throws an InvalidParameterValueException.

Return Value

Type: System.Domain