@cparra/apexdocs 3.0.0-beta.1 → 3.0.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +442 -325
- package/dist/cli/generate.js +1 -1
- package/dist/index.d.ts +15 -17
- package/examples/markdown/docs/miscellaneous/Url.md +10 -8
- package/examples/markdown/force-app/classes/Url.cls +3 -1
- package/examples/markdown-jsconfig/.forceignore +12 -0
- package/examples/markdown-jsconfig/apexdocs.config.mjs +21 -0
- package/examples/markdown-jsconfig/config/project-scratch-def.json +5 -0
- package/examples/markdown-jsconfig/docs/index.md +12 -0
- package/examples/markdown-jsconfig/docs/miscellaneous/Url.md +315 -0
- package/examples/markdown-jsconfig/force-app/classes/Url.cls +196 -0
- package/examples/markdown-jsconfig/package-lock.json +665 -0
- package/examples/markdown-jsconfig/package.json +15 -0
- package/examples/markdown-jsconfig/sfdx-project.json +12 -0
- package/examples/vitepress/apexdocs.config.ts +7 -2
- package/examples/vitepress/docs/index.md +11 -11
- package/examples/vitepress/docs/miscellaneous/BaseClass.md +1 -1
- package/examples/vitepress/docs/miscellaneous/MultiInheritanceClass.md +2 -2
- package/examples/vitepress/docs/miscellaneous/SampleException.md +1 -1
- package/examples/vitepress/docs/miscellaneous/SampleInterface.md +6 -6
- package/examples/vitepress/docs/miscellaneous/Url.md +3 -3
- package/examples/vitepress/docs/sample-enums/SampleEnum.md +3 -3
- package/examples/vitepress/docs/samplegroup/SampleClass.md +5 -5
- package/examples/vitepress/force-app/main/default/classes/SampleClass.cls +1 -1
- package/package.json +2 -2
- package/src/cli/commands/markdown.ts +1 -3
- package/src/core/markdown/__test__/generating-class-docs.spec.ts +1 -129
- package/src/core/markdown/__test__/generating-docs.spec.ts +111 -0
- package/src/core/markdown/__test__/generating-enum-docs.spec.ts +0 -64
- package/src/core/markdown/__test__/generating-interface-docs.spec.ts +0 -64
- package/src/core/markdown/reflection/__test__/filter-scope.spec.ts +306 -0
- package/src/core/shared/types.d.ts +14 -16
- package/src/index.ts +23 -10
package/dist/cli/generate.js
CHANGED
|
@@ -3114,7 +3114,7 @@ const markdownOptions = {
|
|
|
3114
3114
|
},
|
|
3115
3115
|
namespace: {
|
|
3116
3116
|
type: "string",
|
|
3117
|
-
describe: "The package namespace, if any. If
|
|
3117
|
+
describe: "The package namespace, if any. If provided, it will be added to the generated files."
|
|
3118
3118
|
},
|
|
3119
3119
|
sortMembersAlphabetically: {
|
|
3120
3120
|
type: "boolean",
|
package/dist/index.d.ts
CHANGED
|
@@ -1,15 +1,3 @@
|
|
|
1
|
-
import { SetOptional } from 'type-fest';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* The configurable hooks that can be used to modify the output of the generator.
|
|
5
|
-
*/
|
|
6
|
-
type ConfigurableHooks = {
|
|
7
|
-
transformReferenceGuide: TransformReferenceGuide;
|
|
8
|
-
transformDocs: TransformDocs;
|
|
9
|
-
transformDocPage: TransformDocPage;
|
|
10
|
-
transformReference: TransformReference;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
1
|
type LinkingStrategy =
|
|
14
2
|
// Links will be generated using relative paths.
|
|
15
3
|
| 'relative'
|
|
@@ -22,8 +10,8 @@ type LinkingStrategy =
|
|
|
22
10
|
| 'none';
|
|
23
11
|
|
|
24
12
|
type UserDefinedMarkdownConfig = {
|
|
25
|
-
targetGenerator: 'markdown';
|
|
26
13
|
sourceDir: string;
|
|
14
|
+
targetGenerator: 'markdown';
|
|
27
15
|
targetDir: string;
|
|
28
16
|
scope: string[];
|
|
29
17
|
defaultGroupName: string;
|
|
@@ -76,7 +64,17 @@ type Skip = {
|
|
|
76
64
|
readonly _tag: 'Skip';
|
|
77
65
|
};
|
|
78
66
|
|
|
79
|
-
//
|
|
67
|
+
// CONFIGURABLE HOOKS
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* The configurable hooks that can be used to modify the output of the generator.
|
|
71
|
+
*/
|
|
72
|
+
type ConfigurableHooks = {
|
|
73
|
+
transformReferenceGuide: TransformReferenceGuide;
|
|
74
|
+
transformDocs: TransformDocs;
|
|
75
|
+
transformDocPage: TransformDocPage;
|
|
76
|
+
transformReference: TransformReference;
|
|
77
|
+
};
|
|
80
78
|
|
|
81
79
|
type ConfigurableDocPageReference = Omit<DocPageReference, 'source'>;
|
|
82
80
|
|
|
@@ -110,8 +108,8 @@ type TransformDocPage = (
|
|
|
110
108
|
doc: DocPageData,
|
|
111
109
|
) => Partial<ConfigurableDocPageData> | Promise<Partial<ConfigurableDocPageData>>;
|
|
112
110
|
|
|
113
|
-
type ConfigurableMarkdownConfig = Omit<
|
|
114
|
-
declare function defineMarkdownConfig(config: ConfigurableMarkdownConfig): UserDefinedMarkdownConfig
|
|
111
|
+
type ConfigurableMarkdownConfig = Omit<Partial<UserDefinedMarkdownConfig>, 'targetGenerator'>;
|
|
112
|
+
declare function defineMarkdownConfig(config: ConfigurableMarkdownConfig): Partial<UserDefinedMarkdownConfig>;
|
|
115
113
|
declare function skip(): Skip;
|
|
116
114
|
|
|
117
|
-
export { type ConfigurableHooks, type DocPageData, type DocPageReference, type ReferenceGuidePageData, defineMarkdownConfig, skip };
|
|
115
|
+
export { type ConfigurableDocPageData, type ConfigurableDocPageReference, type ConfigurableHooks, type DocPageData, type DocPageReference, type ReferenceGuidePageData, type Skip, type TransformDocPage, type TransformDocs, type TransformReference, type TransformReferenceGuide, defineMarkdownConfig, skip };
|
|
@@ -299,11 +299,13 @@ global static Url getOrgDomainUrl()
|
|
|
299
299
|
getOrgDomainUrl() always returns the login URL for your org, regardless of context. Use that URL when making API calls to your org.
|
|
300
300
|
|
|
301
301
|
#### Example
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
req
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
req.
|
|
309
|
-
|
|
302
|
+
This example uses the Salesforce REST API to get organization limit values. For information on limits, see Limits in the REST API Developer Guide.
|
|
303
|
+
```apex
|
|
304
|
+
Http h = new Http();
|
|
305
|
+
HttpRequest req = new HttpRequest();
|
|
306
|
+
req.setEndpoint(Url.getOrgDomainUrl().toExternalForm()
|
|
307
|
+
+ '/services/data/v44.0/limits');
|
|
308
|
+
req.setMethod('GET');
|
|
309
|
+
req.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionId());
|
|
310
|
+
HttpResponse res = h.send(req);
|
|
311
|
+
```
|
|
@@ -176,7 +176,8 @@ global class Url {
|
|
|
176
176
|
* You don't need a RemoteSiteSetting for your org to interact with the Salesforce APIs using domain URLs retrieved with this method.
|
|
177
177
|
*
|
|
178
178
|
* @example
|
|
179
|
-
*
|
|
179
|
+
* This example uses the Salesforce REST API to get organization limit values. For information on limits, see Limits in the REST API Developer Guide.
|
|
180
|
+
* ```apex
|
|
180
181
|
* Http h = new Http();
|
|
181
182
|
* HttpRequest req = new HttpRequest();
|
|
182
183
|
* req.setEndpoint(Url.getOrgDomainUrl().toExternalForm()
|
|
@@ -184,6 +185,7 @@ global class Url {
|
|
|
184
185
|
* req.setMethod('GET');
|
|
185
186
|
* req.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionId());
|
|
186
187
|
* HttpResponse res = h.send(req);
|
|
188
|
+
* ```
|
|
187
189
|
*
|
|
188
190
|
* @see-also
|
|
189
191
|
* * [Lightning Aura Components Developer Guide: Making API Calls from Apex](https://developer.salesforce.com/docs/atlas.en-us.250.0.lightning.meta/lightning/apex_api_calls.htm)
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# List files or directories below to ignore them when running force:source:push, force:source:pull, and force:source:status
|
|
2
|
+
# More information: https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_exclude_source.htm
|
|
3
|
+
#
|
|
4
|
+
|
|
5
|
+
package.xml
|
|
6
|
+
|
|
7
|
+
# LWC configuration files
|
|
8
|
+
**/jsconfig.json
|
|
9
|
+
**/.eslintrc.json
|
|
10
|
+
|
|
11
|
+
# LWC Jest
|
|
12
|
+
**/__tests__/**
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { defineMarkdownConfig } from '../../dist/index.js';
|
|
2
|
+
|
|
3
|
+
export default defineMarkdownConfig({
|
|
4
|
+
sourceDir: 'force-app',
|
|
5
|
+
scope: ['global', 'public', 'protected', 'private', 'namespaceaccessible'],
|
|
6
|
+
namespace: 'ns',
|
|
7
|
+
transformReferenceGuide: () => {
|
|
8
|
+
return {
|
|
9
|
+
frontmatter: {
|
|
10
|
+
title: 'ApexDocs Reference Guide',
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
},
|
|
14
|
+
transformDocPage: (page) => {
|
|
15
|
+
return {
|
|
16
|
+
frontmatter: {
|
|
17
|
+
title: page.source.name,
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
},
|
|
21
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: ApexDocs Reference Guide
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# Apex Reference Guide
|
|
6
|
+
|
|
7
|
+
## Miscellaneous
|
|
8
|
+
|
|
9
|
+
### [Url](miscellaneous/Url.md)
|
|
10
|
+
|
|
11
|
+
Represents a uniform resource locator (URL) and provides access to parts of the URL.
|
|
12
|
+
Enables access to the base URL used to access your Salesforce org.
|
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Url
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# Url Class
|
|
6
|
+
|
|
7
|
+
Represents a uniform resource locator (URL) and provides access to parts of the URL.
|
|
8
|
+
Enables access to the base URL used to access your Salesforce org.
|
|
9
|
+
|
|
10
|
+
**Usage**
|
|
11
|
+
|
|
12
|
+
Use the methods of the `System.URL` class to create links to objects in your organization. Such objects can be files, images,
|
|
13
|
+
logos, or records that you want to include in external emails, in activities, or in Chatter posts. For example, you can create
|
|
14
|
+
a link to a file uploaded as an attachment to a Chatter post by concatenating the Salesforce base URL with the file ID:
|
|
15
|
+
|
|
16
|
+
```apex
|
|
17
|
+
// Get a file uploaded through Chatter.
|
|
18
|
+
ContentDocument doc = [SELECT Id FROM ContentDocument
|
|
19
|
+
WHERE Title = 'myfile'];
|
|
20
|
+
// Create a link to the file.
|
|
21
|
+
String fullFileURL = URL.getOrgDomainURL().toExternalForm() +
|
|
22
|
+
'/' + doc.id;
|
|
23
|
+
system.debug(fullFileURL);
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
The following example creates a link to a Salesforce record. The full URL is created by concatenating the Salesforce base
|
|
28
|
+
URL with the record ID.
|
|
29
|
+
|
|
30
|
+
```apex
|
|
31
|
+
Account acct = [SELECT Id FROM Account WHERE Name = 'Acme' LIMIT 1];
|
|
32
|
+
String fullRecordURL = URL.getOrgDomainURL().toExternalForm() + '/' + acct.Id;
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
**Version Behavior Changes**
|
|
36
|
+
|
|
37
|
+
In API version 41.0 and later, Apex URL objects are represented by the java.net.URI type, not the java.net.URL type.
|
|
38
|
+
The API version in which the URL object was instantiated determines the behavior of subsequent method calls to the
|
|
39
|
+
specific instance. Salesforce strongly encourages you to use API 41.0 and later versions for fully RFC-compliant URL
|
|
40
|
+
parsing that includes proper handling of edge cases of complex URL structures. API 41.0 and later versions also enforce
|
|
41
|
+
that inputs are valid, RFC-compliant URL or URI strings.
|
|
42
|
+
|
|
43
|
+
* [URL Constructors](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_url.htm#apex_System_URL_constructors)
|
|
44
|
+
* [URL Methods](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_url.htm#apex_System_URL_methods)
|
|
45
|
+
|
|
46
|
+
**See Also**
|
|
47
|
+
* [URL Class](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_url.htm)
|
|
48
|
+
|
|
49
|
+
## Namespace
|
|
50
|
+
ns
|
|
51
|
+
|
|
52
|
+
## Example
|
|
53
|
+
In this example, the base URL and the full request URL of the current Salesforce server instance are retrieved. Next, a URL
|
|
54
|
+
pointing to a specific account object is created. Finally, components of the base and full URL are obtained. This example
|
|
55
|
+
prints out all the results to the debug log output.
|
|
56
|
+
|
|
57
|
+
```apex
|
|
58
|
+
// Create a new account called Acme that we will create a link for later.
|
|
59
|
+
Account myAccount = new Account(Name='Acme');
|
|
60
|
+
insert myAccount;
|
|
61
|
+
|
|
62
|
+
// Get the base URL.
|
|
63
|
+
String sfdcBaseURL = URL.getOrgDomainURL().toExternalForm();
|
|
64
|
+
System.debug('Base URL: ' + sfdcBaseURL );
|
|
65
|
+
|
|
66
|
+
// Get the URL for the current request.
|
|
67
|
+
String currentRequestURL = URL.getCurrentRequestUrl().toExternalForm();
|
|
68
|
+
System.debug('Current request URL: ' + currentRequestURL);
|
|
69
|
+
|
|
70
|
+
// Create the account URL from the base URL.
|
|
71
|
+
String accountURL = URL.getOrgDomainURL().toExternalForm() +
|
|
72
|
+
'/' + myAccount.Id;
|
|
73
|
+
System.debug('URL of a particular account: ' + accountURL);
|
|
74
|
+
|
|
75
|
+
// Get some parts of the base URL.
|
|
76
|
+
System.debug('Host: ' + URL.getOrgDomainURL().getHost());
|
|
77
|
+
System.debug('Protocol: ' + URL.getOrgDomainURL().getProtocol());
|
|
78
|
+
|
|
79
|
+
// Get the query string of the current request.
|
|
80
|
+
System.debug('Query: ' + URL.getCurrentRequestUrl().getQuery());
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## Constructors
|
|
84
|
+
### `Url(spec)`
|
|
85
|
+
|
|
86
|
+
Creates a new instance of the URL class using the specified string representation of the URL.
|
|
87
|
+
|
|
88
|
+
#### Signature
|
|
89
|
+
```apex
|
|
90
|
+
global Url(String spec)
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
#### Parameters
|
|
94
|
+
| Name | Type | Description |
|
|
95
|
+
|------|------|-------------|
|
|
96
|
+
| spec | String | The string to parse as a URL. |
|
|
97
|
+
|
|
98
|
+
---
|
|
99
|
+
|
|
100
|
+
### `Url(context, spec)`
|
|
101
|
+
|
|
102
|
+
Creates a new instance of the URL class by parsing the specified spec within the specified context.
|
|
103
|
+
|
|
104
|
+
**Usage**
|
|
105
|
+
|
|
106
|
+
The new URL is created from the given context URL and the spec argument as described in RFC2396 "Uniform Resource Identifiers : Generic * Syntax" :
|
|
107
|
+
```xml
|
|
108
|
+
<scheme>://<authority><path>?<query>#<fragment>
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
For more information about the arguments of this constructor, see the corresponding URL(java.net.URL, java.lang.String) constructor for Java.
|
|
113
|
+
|
|
114
|
+
#### Signature
|
|
115
|
+
```apex
|
|
116
|
+
global Url(Url context, String spec)
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
#### Parameters
|
|
120
|
+
| Name | Type | Description |
|
|
121
|
+
|------|------|-------------|
|
|
122
|
+
| context | [Url](Url.md) | The context in which to parse the specification. |
|
|
123
|
+
| spec | String | The string to parse as a URL. |
|
|
124
|
+
|
|
125
|
+
---
|
|
126
|
+
|
|
127
|
+
### `Url(protocol, host, file)`
|
|
128
|
+
|
|
129
|
+
Creates a new instance of the URL class using the specified protocol, host, and file on the host. The default port for the specified protocol is used.
|
|
130
|
+
|
|
131
|
+
#### Signature
|
|
132
|
+
```apex
|
|
133
|
+
global Url(String protocol, String host, String file)
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
#### Parameters
|
|
137
|
+
| Name | Type | Description |
|
|
138
|
+
|------|------|-------------|
|
|
139
|
+
| protocol | String | The protocol name for this URL. |
|
|
140
|
+
| host | String | The host name for this URL. |
|
|
141
|
+
| file | String | The file name for this URL. |
|
|
142
|
+
|
|
143
|
+
---
|
|
144
|
+
|
|
145
|
+
### `Url(protocol, host, port, file)`
|
|
146
|
+
|
|
147
|
+
Creates a new instance of the URL class using the specified protocol, host, port number, and file on the host.
|
|
148
|
+
|
|
149
|
+
#### Signature
|
|
150
|
+
```apex
|
|
151
|
+
global Url(String protocol, String host, Integer port, String file)
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
#### Parameters
|
|
155
|
+
| Name | Type | Description |
|
|
156
|
+
|------|------|-------------|
|
|
157
|
+
| protocol | String | The protocol name for this URL. |
|
|
158
|
+
| host | String | The host name for this URL. |
|
|
159
|
+
| port | Integer | The port number for this URL. |
|
|
160
|
+
| file | String | The file name for this URL. |
|
|
161
|
+
|
|
162
|
+
## Methods
|
|
163
|
+
### `getAuthority()`
|
|
164
|
+
|
|
165
|
+
Returns the authority portion of the current URL.
|
|
166
|
+
|
|
167
|
+
#### Signature
|
|
168
|
+
```apex
|
|
169
|
+
global String getAuthority()
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
#### Return Type
|
|
173
|
+
**String**
|
|
174
|
+
|
|
175
|
+
The authority portion of the current URL.
|
|
176
|
+
|
|
177
|
+
---
|
|
178
|
+
|
|
179
|
+
### `getCurrentRequestUrl()`
|
|
180
|
+
|
|
181
|
+
Returns the URL of an entire request on a Salesforce instance.
|
|
182
|
+
|
|
183
|
+
**Usage**
|
|
184
|
+
|
|
185
|
+
An example of a URL for an entire request is https://yourInstance.salesforce.com/apex/myVfPage.apexp.
|
|
186
|
+
|
|
187
|
+
#### Signature
|
|
188
|
+
```apex
|
|
189
|
+
global static Url getCurrentRequestUrl()
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
#### Return Type
|
|
193
|
+
**[Url](Url.md)**
|
|
194
|
+
|
|
195
|
+
The URL of the entire request.
|
|
196
|
+
|
|
197
|
+
---
|
|
198
|
+
|
|
199
|
+
### `getDefPort()`
|
|
200
|
+
|
|
201
|
+
Returns the default port number of the protocol associated with the current URL.
|
|
202
|
+
|
|
203
|
+
**Usage**
|
|
204
|
+
|
|
205
|
+
Returns -1 if the URL scheme or the stream protocol handler for the URL doesn't define a default port number.
|
|
206
|
+
|
|
207
|
+
#### Signature
|
|
208
|
+
```apex
|
|
209
|
+
global Integer getDefPort()
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
#### Return Type
|
|
213
|
+
**Integer**
|
|
214
|
+
|
|
215
|
+
The default port number of the protocol associated with the current URL.
|
|
216
|
+
|
|
217
|
+
---
|
|
218
|
+
|
|
219
|
+
### `getFile()`
|
|
220
|
+
|
|
221
|
+
Returns the file name of the current URL.
|
|
222
|
+
|
|
223
|
+
#### Signature
|
|
224
|
+
```apex
|
|
225
|
+
global String getFile()
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
#### Return Type
|
|
229
|
+
**String**
|
|
230
|
+
|
|
231
|
+
The file name of the current URL.
|
|
232
|
+
|
|
233
|
+
---
|
|
234
|
+
|
|
235
|
+
### `getFileFieldURL(entityId, fieldName)`
|
|
236
|
+
|
|
237
|
+
Returns the download URL for a file attachment.
|
|
238
|
+
|
|
239
|
+
#### Signature
|
|
240
|
+
```apex
|
|
241
|
+
global static String getFileFieldURL(String entityId, String fieldName)
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
#### Parameters
|
|
245
|
+
| Name | Type | Description |
|
|
246
|
+
|------|------|-------------|
|
|
247
|
+
| entityId | String | Specifies the ID of the entity that holds the file data. |
|
|
248
|
+
| fieldName | String | Specifies the API name of a file field component, such as `AttachmentBody` . |
|
|
249
|
+
|
|
250
|
+
#### Return Type
|
|
251
|
+
**String**
|
|
252
|
+
|
|
253
|
+
The download URL for the file attachment.
|
|
254
|
+
|
|
255
|
+
#### Example
|
|
256
|
+
String fileURL =
|
|
257
|
+
URL.getFileFieldURL(
|
|
258
|
+
'087000000000123' ,
|
|
259
|
+
'AttachmentBody');
|
|
260
|
+
|
|
261
|
+
---
|
|
262
|
+
|
|
263
|
+
### `getHost()`
|
|
264
|
+
|
|
265
|
+
Returns the host name of the current URL.
|
|
266
|
+
|
|
267
|
+
#### Signature
|
|
268
|
+
```apex
|
|
269
|
+
global String getHost()
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
#### Return Type
|
|
273
|
+
**String**
|
|
274
|
+
|
|
275
|
+
The host name of the current URL.
|
|
276
|
+
|
|
277
|
+
---
|
|
278
|
+
|
|
279
|
+
### `getOrgDomainUrl()`
|
|
280
|
+
|
|
281
|
+
Returns the canonical URL for your org. For example, https://MyDomainName.my.salesforce.com.
|
|
282
|
+
|
|
283
|
+
**Usage**
|
|
284
|
+
|
|
285
|
+
Use getOrgDomainUrl() to interact with Salesforce REST and SOAP APIs in Apex code. Get endpoints for User Interface API calls, for creating and customizing picklist value sets and custom fields, and more.
|
|
286
|
+
|
|
287
|
+
`getOrgDomainUrl()` can access the domain URL only for the org in which the Apex code is running.
|
|
288
|
+
|
|
289
|
+
You don't need a RemoteSiteSetting for your org to interact with the Salesforce APIs using domain URLs retrieved with this method.
|
|
290
|
+
|
|
291
|
+
**See Also**
|
|
292
|
+
|
|
293
|
+
* [Lightning Aura Components Developer Guide: Making API Calls from Apex](https://developer.salesforce.com/docs/atlas.en-us.250.0.lightning.meta/lightning/apex_api_calls.htm)
|
|
294
|
+
|
|
295
|
+
#### Signature
|
|
296
|
+
```apex
|
|
297
|
+
global static Url getOrgDomainUrl()
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
#### Return Type
|
|
301
|
+
**[Url](Url.md)**
|
|
302
|
+
|
|
303
|
+
getOrgDomainUrl() always returns the login URL for your org, regardless of context. Use that URL when making API calls to your org.
|
|
304
|
+
|
|
305
|
+
#### Example
|
|
306
|
+
This example uses the Salesforce REST API to get organization limit values. For information on limits, see Limits in the REST API Developer Guide.
|
|
307
|
+
```apex
|
|
308
|
+
Http h = new Http();
|
|
309
|
+
HttpRequest req = new HttpRequest();
|
|
310
|
+
req.setEndpoint(Url.getOrgDomainUrl().toExternalForm()
|
|
311
|
+
+ '/services/data/v44.0/limits');
|
|
312
|
+
req.setMethod('GET');
|
|
313
|
+
req.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionId());
|
|
314
|
+
HttpResponse res = h.send(req);
|
|
315
|
+
```
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description Represents a uniform resource locator (URL) and provides access to parts of the URL.
|
|
3
|
+
* Enables access to the base URL used to access your Salesforce org.
|
|
4
|
+
*
|
|
5
|
+
* @usage
|
|
6
|
+
* Use the methods of the `System.URL` class to create links to objects in your organization. Such objects can be files, images,
|
|
7
|
+
* logos, or records that you want to include in external emails, in activities, or in Chatter posts. For example, you can create
|
|
8
|
+
* a link to a file uploaded as an attachment to a Chatter post by concatenating the Salesforce base URL with the file ID:
|
|
9
|
+
*
|
|
10
|
+
* ```apex
|
|
11
|
+
* // Get a file uploaded through Chatter.
|
|
12
|
+
* ContentDocument doc = [SELECT Id FROM ContentDocument
|
|
13
|
+
* WHERE Title = 'myfile'];
|
|
14
|
+
* // Create a link to the file.
|
|
15
|
+
* String fullFileURL = URL.getOrgDomainURL().toExternalForm() +
|
|
16
|
+
* '/' + doc.id;
|
|
17
|
+
* system.debug(fullFileURL);
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* The following example creates a link to a Salesforce record. The full URL is created by concatenating the Salesforce base
|
|
21
|
+
* URL with the record ID.
|
|
22
|
+
*
|
|
23
|
+
* ```apex
|
|
24
|
+
* Account acct = [SELECT Id FROM Account WHERE Name = 'Acme' LIMIT 1];
|
|
25
|
+
* String fullRecordURL = URL.getOrgDomainURL().toExternalForm() + '/' + acct.Id;
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* In this example, the base URL and the full request URL of the current Salesforce server instance are retrieved. Next, a URL
|
|
30
|
+
* pointing to a specific account object is created. Finally, components of the base and full URL are obtained. This example
|
|
31
|
+
* prints out all the results to the debug log output.
|
|
32
|
+
*
|
|
33
|
+
* ```apex
|
|
34
|
+
* // Create a new account called Acme that we will create a link for later.
|
|
35
|
+
* Account myAccount = new Account(Name='Acme');
|
|
36
|
+
* insert myAccount;
|
|
37
|
+
*
|
|
38
|
+
* // Get the base URL.
|
|
39
|
+
* String sfdcBaseURL = URL.getOrgDomainURL().toExternalForm();
|
|
40
|
+
* System.debug('Base URL: ' + sfdcBaseURL );
|
|
41
|
+
*
|
|
42
|
+
* // Get the URL for the current request.
|
|
43
|
+
* String currentRequestURL = URL.getCurrentRequestUrl().toExternalForm();
|
|
44
|
+
* System.debug('Current request URL: ' + currentRequestURL);
|
|
45
|
+
*
|
|
46
|
+
* // Create the account URL from the base URL.
|
|
47
|
+
* String accountURL = URL.getOrgDomainURL().toExternalForm() +
|
|
48
|
+
* '/' + myAccount.Id;
|
|
49
|
+
* System.debug('URL of a particular account: ' + accountURL);
|
|
50
|
+
*
|
|
51
|
+
* // Get some parts of the base URL.
|
|
52
|
+
* System.debug('Host: ' + URL.getOrgDomainURL().getHost());
|
|
53
|
+
* System.debug('Protocol: ' + URL.getOrgDomainURL().getProtocol());
|
|
54
|
+
*
|
|
55
|
+
* // Get the query string of the current request.
|
|
56
|
+
* System.debug('Query: ' + URL.getCurrentRequestUrl().getQuery());
|
|
57
|
+
* ```
|
|
58
|
+
*
|
|
59
|
+
* @version-behavior-changes
|
|
60
|
+
* In API version 41.0 and later, Apex URL objects are represented by the java.net.URI type, not the java.net.URL type.
|
|
61
|
+
* The API version in which the URL object was instantiated determines the behavior of subsequent method calls to the
|
|
62
|
+
* specific instance. Salesforce strongly encourages you to use API 41.0 and later versions for fully RFC-compliant URL
|
|
63
|
+
* parsing that includes proper handling of edge cases of complex URL structures. API 41.0 and later versions also enforce
|
|
64
|
+
* that inputs are valid, RFC-compliant URL or URI strings.
|
|
65
|
+
*
|
|
66
|
+
* * [URL Constructors](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_url.htm#apex_System_URL_constructors)
|
|
67
|
+
* * [URL Methods](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_url.htm#apex_System_URL_methods)
|
|
68
|
+
*
|
|
69
|
+
* **See Also**
|
|
70
|
+
* * [URL Class](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_url.htm)
|
|
71
|
+
*/
|
|
72
|
+
global class Url {
|
|
73
|
+
/**
|
|
74
|
+
* @description Creates a new instance of the URL class using the specified string representation of the URL.
|
|
75
|
+
* @param spec The string to parse as a URL.
|
|
76
|
+
*/
|
|
77
|
+
global Url(String spec) { }
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* @description Creates a new instance of the URL class by parsing the specified spec within the specified context.
|
|
81
|
+
* @param context The context in which to parse the specification.
|
|
82
|
+
* @param spec The string to parse as a URL.
|
|
83
|
+
*
|
|
84
|
+
* @usage
|
|
85
|
+
* The new URL is created from the given context URL and the spec argument as described in RFC2396 "Uniform Resource Identifiers : Generic * Syntax" :
|
|
86
|
+
* ```xml
|
|
87
|
+
* <scheme>://<authority><path>?<query>#<fragment>
|
|
88
|
+
* ```
|
|
89
|
+
*
|
|
90
|
+
* For more information about the arguments of this constructor, see the corresponding URL(java.net.URL, java.lang.String) constructor for Java.
|
|
91
|
+
*/
|
|
92
|
+
global Url(Url context, String spec) { }
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* @description Creates a new instance of the URL class using the specified protocol, host, and file on the host. The default port for the specified protocol is used.
|
|
96
|
+
* @param protocol The protocol name for this URL.
|
|
97
|
+
* @param host The host name for this URL.
|
|
98
|
+
* @param file The file name for this URL.
|
|
99
|
+
*/
|
|
100
|
+
global Url(String protocol, String host, String file) {}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* @description Creates a new instance of the URL class using the specified protocol, host, port number, and file on the host.
|
|
104
|
+
* @param protocol The protocol name for this URL.
|
|
105
|
+
* @param host The host name for this URL.
|
|
106
|
+
* @param port The port number for this URL.
|
|
107
|
+
* @param file The file name for this URL.
|
|
108
|
+
*/
|
|
109
|
+
global Url(String protocol, String host, Integer port, String file) {}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* @description Returns the authority portion of the current URL.
|
|
113
|
+
* @return The authority portion of the current URL.
|
|
114
|
+
*/
|
|
115
|
+
global String getAuthority() {
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* @description Returns the URL of an entire request on a Salesforce instance.
|
|
121
|
+
* @return The URL of the entire request.
|
|
122
|
+
* @usage An example of a URL for an entire request is https://yourInstance.salesforce.com/apex/myVfPage.apexp.
|
|
123
|
+
*/
|
|
124
|
+
global static Url getCurrentRequestUrl() {
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* @description Returns the default port number of the protocol associated with the current URL.
|
|
130
|
+
* @return The default port number of the protocol associated with the current URL.
|
|
131
|
+
* @usage Returns -1 if the URL scheme or the stream protocol handler for the URL doesn't define a default port number.
|
|
132
|
+
*/
|
|
133
|
+
global Integer getDefPort() {
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* @description Returns the file name of the current URL.
|
|
139
|
+
* @return The file name of the current URL.
|
|
140
|
+
*/
|
|
141
|
+
global String getFile() {
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* @description Returns the download URL for a file attachment.
|
|
147
|
+
* @param entityId Specifies the ID of the entity that holds the file data.
|
|
148
|
+
* @param fieldName Specifies the API name of a file field component, such as `AttachmentBody`.
|
|
149
|
+
* @return The download URL for the file attachment.
|
|
150
|
+
* @example
|
|
151
|
+
* String fileURL =
|
|
152
|
+
* URL.getFileFieldURL(
|
|
153
|
+
* '087000000000123' ,
|
|
154
|
+
* 'AttachmentBody');
|
|
155
|
+
*/
|
|
156
|
+
global static String getFileFieldURL(String entityId, String fieldName) {
|
|
157
|
+
return null;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* @description Returns the host name of the current URL.
|
|
162
|
+
* @return The host name of the current URL.
|
|
163
|
+
*/
|
|
164
|
+
global String getHost() {
|
|
165
|
+
return null;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* @description Returns the canonical URL for your org. For example, https://MyDomainName.my.salesforce.com.
|
|
170
|
+
* @return getOrgDomainUrl() always returns the login URL for your org, regardless of context. Use that URL when making API calls to your org.
|
|
171
|
+
* @usage
|
|
172
|
+
* Use getOrgDomainUrl() to interact with Salesforce REST and SOAP APIs in Apex code. Get endpoints for User Interface API calls, for creating and customizing picklist value sets and custom fields, and more.
|
|
173
|
+
*
|
|
174
|
+
* `getOrgDomainUrl()` can access the domain URL only for the org in which the Apex code is running.
|
|
175
|
+
*
|
|
176
|
+
* You don't need a RemoteSiteSetting for your org to interact with the Salesforce APIs using domain URLs retrieved with this method.
|
|
177
|
+
*
|
|
178
|
+
* @example
|
|
179
|
+
* This example uses the Salesforce REST API to get organization limit values. For information on limits, see Limits in the REST API Developer Guide.
|
|
180
|
+
* ```apex
|
|
181
|
+
* Http h = new Http();
|
|
182
|
+
* HttpRequest req = new HttpRequest();
|
|
183
|
+
* req.setEndpoint(Url.getOrgDomainUrl().toExternalForm()
|
|
184
|
+
* + '/services/data/v44.0/limits');
|
|
185
|
+
* req.setMethod('GET');
|
|
186
|
+
* req.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionId());
|
|
187
|
+
* HttpResponse res = h.send(req);
|
|
188
|
+
* ```
|
|
189
|
+
*
|
|
190
|
+
* @see-also
|
|
191
|
+
* * [Lightning Aura Components Developer Guide: Making API Calls from Apex](https://developer.salesforce.com/docs/atlas.en-us.250.0.lightning.meta/lightning/apex_api_calls.htm)
|
|
192
|
+
*/
|
|
193
|
+
global static Url getOrgDomainUrl() {
|
|
194
|
+
return null;
|
|
195
|
+
}
|
|
196
|
+
}
|