Newer Version Available
URL Class
Namespace
Usage
Example
URL Constructors
The following are constructors for URL.
Url(spec)
Signature
public Url(String spec)
Parameters
- spec
- Type: String
- The string to parse as a URL.
Url(context, spec)
Signature
public Url(Url context, String spec)
Parameters
Usage
For more information about the arguments of this constructor, see the corresponding URL(java.net.URL, java.lang.String) constructor for Java.
Url(protocol, host, file)
Signature
public Url(String protocol, String host, String file)
URL Methods
The following are methods for URL.
getAuthority()
Signature
public String getAuthority()
Return Value
Type: String
getCurrentRequestUrl()
Signature
public static System.URL getCurrentRequestUrl()
Return Value
Type: System.URL
Usage
An example of a URL for an entire request is https://yourInstance.salesforce.com/apex/myVfPage.apexp.
getDefaultPort()
Signature
public Integer getDefaultPort()
Return Value
Type: Integer
Usage
Returns -1 if the URL scheme or the stream protocol handler for the URL doesn't define a default port number.
getFile()
Signature
public String getFile()
Return Value
Type: String
getFileFieldURL(entityId, fieldName)
Signature
public static String getFileFieldURL(String entityId, String fieldName)
Parameters
Return Value
Type: String
Usage
Example:
Example
getHost()
Signature
public String getHost()
Return Value
Type: String
getPath()
Signature
public String getPath()
Return Value
Type: String
getProtocol()
Signature
public String getProtocol()
Return Value
Type: String
getQuery()
Signature
public String getQuery()
Return Value
Type: String
Usage
Returns null if no query portion exists.
getRef()
Signature
public String getRef()
Return Value
Type: String
Usage
Returns null if no query portion exists.
getSalesforceBaseUrl()
Signature
public static System.URL getSalesforceBaseUrl()
Return Value
Type: System.URL
Usage
An example of an instance URL is https://yourInstance.salesforce.com/.
getUserInfo()
Signature
public String getUserInfo()
Return Value
Type: String
Usage
Returns null if no UserInfo portion exists.
sameFile(URLToCompare)
Signature
public Boolean sameFile(System.URL URLToCompare)
Parameters
- URLToCompare
- Type: System.URL
Return Value
Type: Boolean
Returns true if both URL objects reference the same remote resource; otherwise, returns false.
Usage
For more information about the syntax of URIs and fragment components, see RFC3986.
toExternalForm()
Signature
public String toExternalForm()
Return Value
Type: String