No Results
Search Tips:
- Please consider misspellings
- Try different search keywords
Newer Version Available
URL Class
Namespace
Usage
1// Get a file uploaded through Chatter.
2ContentDocument doc = [SELECT Id FROM ContentDocument
3 WHERE Title = 'myfile'];
4// Create a link to the file.
5String fullFileURL = URL.getSalesforceBaseUrl().toExternalForm() +
6 '/' + doc.id;
7system.debug(fullFileURL);Example
1swfobject.registerObject("clippy.codeblock-2", "9");// Create a new account called Acme that we will create a link for later.
2Account myAccount = new Account(Name='Acme');
3insert myAccount;
4
5// Get the base URL.
6String sfdcBaseURL = URL.getSalesforceBaseUrl().toExternalForm();
7System.debug('Base URL: ' + sfdcBaseURL );
8
9// Get the URL for the current request.
10String currentRequestURL = URL.getCurrentRequestUrl().toExternalForm();
11System.debug('Current request URL: ' + currentRequestURL);
12
13// Create the account URL from the base URL.
14String accountURL = URL.getSalesforceBaseUrl().toExternalForm() +
15 '/' + myAccount.Id;
16System.debug('URL of a particular account: ' + accountURL);
17
18// Get some parts of the base URL.
19System.debug('Host: ' + URL.getSalesforceBaseUrl().getHost());
20System.debug('Protocol: ' + URL.getSalesforceBaseUrl().getProtocol());
21
22// Get the query string of the current request.
23System.debug('Query: ' + URL.getCurrentRequestUrl().getQuery());URL Constructors
The following are constructors for URL.
URL(String)
Signature
public Url(String spec)
Parameters
- spec
- Type: String
- The string to parse as a URL.
URL(URL, String)
Signature
public Url(Url context, String spec)
Parameters
Usage
1<scheme>://<authority><path>?<query>#<fragment>For more information about the arguments of this constructor, see the corresponding URL(java.net.URL, java.lang.String) constructor for Java.
URL(String, String, String)
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://na1.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(String, String)
Signature
public static String getFileFieldURL(String entityId, String fieldName)
Parameters
Return Value
Type: String
Usage
Example:
Example
1String fileURL =
2 URL.getFileFieldURL(
3 '087000000000123' ,
4 'AttachmentBody');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://na1.salesforce.com.
getUserInfo()
Signature
public String getUserInfo()
Return Value
Type: String
Usage
Returns null if no UserInfo portion exists.
sameFile(System.URL)
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