|
1 | | -# Apex Reference Guide |
| 1 | +# Reference Guide |
2 | 2 |
|
3 | 3 | ## Miscellaneous |
4 | 4 |
|
5 | | -### [BaseClass](miscellaneous/BaseClass.md) |
6 | | - |
7 | | -### [MultiInheritanceClass](miscellaneous/MultiInheritanceClass.md) |
8 | | - |
9 | | -### [ParentInterface](miscellaneous/ParentInterface.md) |
10 | | - |
11 | | -### [ReferencedEnum](miscellaneous/ReferencedEnum.md) |
12 | | - |
13 | | -### [SampleException](miscellaneous/SampleException.md) |
14 | | - |
15 | | -This is a sample exception. |
16 | | - |
17 | | -### [SampleInterface](miscellaneous/SampleInterface.md) |
18 | | - |
19 | | -This is a sample interface |
20 | | - |
21 | | -### [Url](miscellaneous/Url.md) |
22 | | - |
23 | | -Represents a uniform resource locator (URL) and provides access to parts of the URL. |
24 | | -Enables access to the base URL used to access your Salesforce org. |
25 | | - |
26 | | -## Usage |
27 | | -Use the methods of the `System.URL` class to create links to objects in your organization. Such objects can be files, images, |
28 | | -logos, or records that you want to include in external emails, in activities, or in Chatter posts. For example, you can create |
29 | | -a link to a file uploaded as an attachment to a Chatter post by concatenating the Salesforce base URL with the file ID: |
30 | | - |
31 | | -```apex |
32 | | -// Get a file uploaded through Chatter. |
33 | | -ContentDocument doc = [SELECT Id FROM ContentDocument |
34 | | - WHERE Title = 'myfile']; |
35 | | -// Create a link to the file. |
36 | | -String fullFileURL = URL.getOrgDomainURL().toExternalForm() + |
37 | | -'/' + doc.id; |
38 | | -system.debug(fullFileURL); |
39 | | -``` |
40 | | - |
41 | | - |
42 | | -The following example creates a link to a Salesforce record. The full URL is created by concatenating the Salesforce base |
43 | | -URL with the record ID. |
44 | | - |
45 | | -```ape |
46 | | -Account acct = [SELECT Id FROM Account WHERE Name = 'Acme' LIMIT 1]; |
47 | | -String fullRecordURL = URL.getOrgDomainURL().toExternalForm() + '/' + acct.Id; |
48 | | -``` |
49 | | - |
50 | | - |
51 | | -## Example |
52 | | -In this example, the base URL and the full request URL of the current Salesforce server instance are retrieved. Next, a URL |
53 | | -pointing to a specific account object is created. Finally, components of the base and full URL are obtained. This example |
54 | | -prints out all the results to the debug log output. |
55 | | - |
56 | | -```apex |
57 | | -// Create a new account called Acme that we will create a link for later. |
58 | | -Account myAccount = new Account(Name='Acme'); |
59 | | -insert myAccount; |
60 | | -
|
61 | | -// Get the base URL. |
62 | | -String sfdcBaseURL = URL.getOrgDomainURL().toExternalForm(); |
63 | | -System.debug('Base URL: ' + sfdcBaseURL ); |
64 | | -
|
65 | | -// Get the URL for the current request. |
66 | | -String currentRequestURL = URL.getCurrentRequestUrl().toExternalForm(); |
67 | | -System.debug('Current request URL: ' + currentRequestURL); |
68 | | -
|
69 | | -// Create the account URL from the base URL. |
70 | | -String accountURL = URL.getOrgDomainURL().toExternalForm() + |
71 | | - '/' + myAccount.Id; |
72 | | -System.debug('URL of a particular account: ' + accountURL); |
73 | | -
|
74 | | -// Get some parts of the base URL. |
75 | | -System.debug('Host: ' + URL.getOrgDomainURL().getHost()); |
76 | | -System.debug('Protocol: ' + URL.getOrgDomainURL().getProtocol()); |
77 | | -
|
78 | | -// Get the query string of the current request. |
79 | | -System.debug('Query: ' + URL.getCurrentRequestUrl().getQuery()); |
80 | | -``` |
81 | | - |
82 | | - |
83 | | -## Version Behavior Changes |
84 | | -In API version 41.0 and later, Apex URL objects are represented by the java.net.URI type, not the java.net.URL type. |
85 | | -The API version in which the URL object was instantiated determines the behavior of subsequent method calls to the |
86 | | -specific instance. Salesforce strongly encourages you to use API 41.0 and later versions for fully RFC-compliant URL |
87 | | -parsing that includes proper handling of edge cases of complex URL structures. API 41.0 and later versions also enforce |
88 | | -that inputs are valid, RFC-compliant URL or URI strings. |
89 | | - |
90 | | -* [URL Constructors](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_url.htm#apex_System_URL_constructors) |
91 | | -* [URL Methods](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_url.htm#apex_System_URL_methods) |
92 | | - |
93 | | -**See Also** |
94 | | -* [URL Class](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_url.htm) |
95 | | - |
96 | | -## Sample Enums |
97 | | - |
98 | | -### [SampleEnum](sample-enums/SampleEnum.md) |
99 | | - |
100 | | -This is a sample enum. This references [ReferencedEnum](miscellaneous/ReferencedEnum.md) . |
101 | | - |
102 | | -This description has several lines |
103 | | - |
104 | | -## SampleGroup |
105 | | - |
106 | | -### [SampleClass](samplegroup/SampleClass.md) |
107 | | - |
108 | | -aliquip ex sunt officia ullamco anim deserunt magna aliquip nisi eiusmod in sit officia veniam ex |
109 | | -deserunt ea officia exercitation laboris enim in duis quis enim eiusmod eu amet cupidatat. |
| 5 | +### [MultiInheritanceClass](miscellaneous/MultiInheritanceClass.md) |
0 commit comments