@cparra/apexdocs 3.0.0-rc.0 → 3.0.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/README.md +50 -571
- package/dist/cli/generate.js +73 -3094
- package/dist/defaults-BcE8DTat.js +13 -0
- package/dist/defaults-D07y_bq4.js +40 -0
- package/dist/defaults-gPzwP66p.js +14 -0
- package/dist/index.d.ts +35 -3
- package/dist/index.js +90 -2
- package/dist/logger-BEbUIfqN.js +3282 -0
- package/dist/logger-BGuf1PnL.js +3281 -0
- package/dist/logger-CWBRF2za.js +3284 -0
- package/dist/logger-CdBmDEN1.js +3283 -0
- package/dist/logger-Ce4QqPFR.js +3278 -0
- package/dist/logger-CyEVYaAC.js +3284 -0
- package/dist/logger-D7a83ycP.js +3277 -0
- package/dist/logger-DGaHeBKk.js +3279 -0
- package/dist/logger-Dqhl_lO_.js +3278 -0
- package/dist/logger-aySSWi0G.js +3280 -0
- package/dist/logger-qLCcAtiy.js +3284 -0
- package/examples/README.md +5 -0
- package/examples/docsify/README.md +17 -0
- package/examples/docsify/apexdocs.config.ts +13 -0
- package/examples/docsify/classes/ASampleClass.cls +57 -0
- package/examples/docsify/classes/CodeControl.cls +19 -0
- package/examples/docsify/classes/SampleClass.cls +95 -0
- package/examples/docsify/classes/SampleInterface.cls +17 -0
- package/examples/docsify/classes/SomeDto.cls +122 -0
- package/examples/docsify/docs/.nojekyll +0 -0
- package/examples/docsify/docs/README.md +25 -0
- package/examples/docsify/docs/_config.yml +1 -0
- package/examples/docsify/docs/index.html +22 -0
- package/examples/docsify/docs/miscellaneous/ASampleClass.md +88 -0
- package/examples/docsify/docs/miscellaneous/CodeControl.md +107 -0
- package/examples/docsify/docs/miscellaneous/SomeDto.md +244 -0
- package/examples/docsify/docs/sample-classes/SampleClass.md +171 -0
- package/examples/docsify/docs/sample-interfaces/SampleInterface.md +36 -0
- package/examples/docsify/package-lock.json +2459 -0
- package/examples/docsify/package.json +14 -0
- package/examples/imported/.forceignore +12 -0
- package/examples/imported/README.md +6 -0
- package/examples/imported/config/project-scratch-def.json +5 -0
- package/examples/imported/docs/index.md +109 -0
- package/examples/imported/docs/miscellaneous/BaseClass.md +13 -0
- package/examples/imported/docs/miscellaneous/MultiInheritanceClass.md +69 -0
- package/examples/imported/docs/miscellaneous/ParentInterface.md +12 -0
- package/examples/imported/docs/miscellaneous/ReferencedEnum.md +5 -0
- package/examples/imported/docs/miscellaneous/SampleException.md +21 -0
- package/examples/imported/docs/miscellaneous/SampleInterface.md +113 -0
- package/examples/imported/docs/miscellaneous/Url.md +308 -0
- package/examples/imported/docs/sample-enums/SampleEnum.md +33 -0
- package/examples/imported/docs/samplegroup/SampleClass.md +167 -0
- package/examples/imported/force-app/classes/BaseClass.cls +3 -0
- package/examples/imported/force-app/classes/MultiInheritanceClass.cls +1 -0
- package/examples/imported/force-app/classes/ParentInterface.cls +3 -0
- package/examples/imported/force-app/classes/ReferencedEnum.cls +3 -0
- package/examples/imported/force-app/classes/SampleClass.cls +72 -0
- package/examples/imported/force-app/classes/SampleInterface.cls +50 -0
- package/examples/imported/force-app/classes/Url.cls +196 -0
- package/examples/imported/package-lock.json +665 -0
- package/examples/imported/package.json +6 -0
- package/examples/imported/scripts/process-docs.mjs +16 -0
- package/examples/imported/sfdx-project.json +12 -0
- package/examples/markdown/README.md +7 -0
- package/examples/markdown-jsconfig/README.md +9 -0
- package/examples/markdown-jsconfig/apexdocs.config.mjs +1 -0
- package/examples/markdown-jsconfig/docs/index.md +1 -1
- package/examples/open-api/README.md +5 -0
- package/examples/open-api/docs/openapi.json +2 -570
- package/examples/vitepress/README.md +25 -0
- package/examples/vitepress/apexdocs.config.ts +2 -0
- package/examples/vitepress/force-app/main/default/classes/{SampleClass.cls → feature-a/SampleClass.cls} +1 -0
- package/examples/vitepress/force-app/main/default/classes/feature-a/SampleEnum.cls +30 -0
- package/examples/vitepress/force-app/main/default/classes/feature-a/SampleException.cls +17 -0
- package/package.json +2 -2
- package/src/application/Apexdocs.ts +16 -19
- package/src/application/__tests__/apex-file-reader.spec.ts +108 -67
- package/src/application/apex-file-reader.ts +1 -0
- package/src/application/generators/openapi.ts +17 -13
- package/src/cli/args.ts +12 -3
- package/src/cli/commands/markdown.ts +14 -9
- package/src/cli/commands/openapi.ts +5 -5
- package/src/cli/generate.ts +20 -4
- package/src/core/markdown/__test__/generating-class-docs.spec.ts +14 -257
- package/src/core/markdown/__test__/generating-docs.spec.ts +271 -4
- package/src/core/markdown/__test__/generating-enum-docs.spec.ts +4 -264
- package/src/core/markdown/__test__/generating-interface-docs.spec.ts +4 -232
- package/src/core/markdown/__test__/generating-reference-guide.spec.ts +17 -1
- package/src/core/markdown/__test__/test-helpers.ts +3 -1
- package/src/core/markdown/adapters/__tests__/interface-adapter.spec.ts +3 -1
- package/src/core/markdown/adapters/renderable-to-page-data.ts +6 -4
- package/src/core/markdown/generate-docs.ts +13 -15
- package/src/core/markdown/reflection/__test__/filter-scope.spec.ts +2 -18
- package/src/core/markdown/reflection/__test__/helpers.ts +18 -0
- package/src/core/markdown/reflection/__test__/remove-excluded-tags.spec.ts +200 -0
- package/src/core/markdown/reflection/remove-excluded-tags.ts +168 -0
- package/src/core/markdown/reflection/{sort-members.ts → sort-types-and-members.ts} +7 -5
- package/src/core/markdown/templates/reference-guide.ts +2 -2
- package/src/core/openapi/__tests__/open-api-docs-processor.spec.ts +6 -3
- package/src/core/openapi/open-api-docs-processor.ts +3 -3
- package/src/core/openapi/parser.ts +5 -2
- package/src/core/shared/types.d.ts +4 -2
- package/src/defaults.ts +15 -3
- package/src/index.ts +65 -4
- package/src/util/error-logger.ts +36 -36
- package/src/util/logger.ts +18 -11
- /package/examples/{vitepress/force-app/main/default → imported/force-app}/classes/SampleEnum.cls +0 -0
- /package/examples/{vitepress/force-app/main/default → imported/force-app}/classes/SampleException.cls +0 -0
- /package/examples/vitepress/force-app/main/default/classes/{SampleInterface.cls → feature-a/SampleInterface.cls} +0 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "apexdocs-docsify-example",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"dependencies": {
|
|
5
|
+
"docsify-cli": "^4.4.1"
|
|
6
|
+
},
|
|
7
|
+
"devDependencies": {
|
|
8
|
+
"ts-node": "^10.9.2"
|
|
9
|
+
},
|
|
10
|
+
"scripts": {
|
|
11
|
+
"generate": "ts-node ../../src/cli/generate.ts markdown",
|
|
12
|
+
"serve": "docsify serve docs"
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -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,109 @@
|
|
|
1
|
+
# Apex Reference Guide
|
|
2
|
+
|
|
3
|
+
## Miscellaneous
|
|
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.
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# MultiInheritanceClass Class
|
|
2
|
+
|
|
3
|
+
**Inheritance**
|
|
4
|
+
|
|
5
|
+
[SampleClass](../samplegroup/SampleClass.md) < [BaseClass](BaseClass.md)
|
|
6
|
+
|
|
7
|
+
## Fields
|
|
8
|
+
### `sampleEnumFromBase`
|
|
9
|
+
|
|
10
|
+
*Inherited*
|
|
11
|
+
|
|
12
|
+
#### Signature
|
|
13
|
+
```apex
|
|
14
|
+
public sampleEnumFromBase
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
#### Type
|
|
18
|
+
[SampleEnum](../sample-enums/SampleEnum.md)
|
|
19
|
+
|
|
20
|
+
## Properties
|
|
21
|
+
### Group Name
|
|
22
|
+
#### `someProperty`
|
|
23
|
+
|
|
24
|
+
*Inherited*
|
|
25
|
+
|
|
26
|
+
##### Signature
|
|
27
|
+
```apex
|
|
28
|
+
public someProperty
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
##### Type
|
|
32
|
+
String
|
|
33
|
+
|
|
34
|
+
## Methods
|
|
35
|
+
### Available Methods
|
|
36
|
+
#### `doSomething()`
|
|
37
|
+
|
|
38
|
+
*Inherited*
|
|
39
|
+
|
|
40
|
+
##### Signature
|
|
41
|
+
```apex
|
|
42
|
+
public void doSomething()
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
##### Return Type
|
|
46
|
+
**void**
|
|
47
|
+
|
|
48
|
+
### Deprecated Methods
|
|
49
|
+
#### `sayHello()`
|
|
50
|
+
|
|
51
|
+
*Inherited*
|
|
52
|
+
|
|
53
|
+
`DEPRECATED`
|
|
54
|
+
|
|
55
|
+
This is a sample method.
|
|
56
|
+
|
|
57
|
+
##### Signature
|
|
58
|
+
```apex
|
|
59
|
+
public virtual String sayHello()
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
##### Return Type
|
|
63
|
+
**String**
|
|
64
|
+
|
|
65
|
+
A string value.
|
|
66
|
+
|
|
67
|
+
##### Example
|
|
68
|
+
SampleClass sample = new SampleClass();
|
|
69
|
+
sample.doSomething();
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# SampleException Class
|
|
2
|
+
|
|
3
|
+
This is a sample exception.
|
|
4
|
+
|
|
5
|
+
**Usage**
|
|
6
|
+
|
|
7
|
+
You can use the exception the following way.
|
|
8
|
+
You can also take a look at [SampleClass](../samplegroup/SampleClass.md) to see how it is used.
|
|
9
|
+
This is a dangerous HTML tag: <script>alert('Hello');</script>
|
|
10
|
+
|
|
11
|
+
```apex
|
|
12
|
+
try {
|
|
13
|
+
throw new SampleException();
|
|
14
|
+
} catch (SampleException e) {
|
|
15
|
+
System.debug('Caught exception');
|
|
16
|
+
}
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
**Inheritance**
|
|
20
|
+
|
|
21
|
+
Exception
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
# SampleInterface Interface
|
|
2
|
+
|
|
3
|
+
`NAMESPACEACCESSIBLE`
|
|
4
|
+
|
|
5
|
+
This is a sample interface
|
|
6
|
+
|
|
7
|
+
**Mermaid**
|
|
8
|
+
|
|
9
|
+
```mermaid
|
|
10
|
+
graph TD
|
|
11
|
+
A[SampleInterface] -->|extends| B[ParentInterface]
|
|
12
|
+
B -->|extends| C[GrandParentInterface]
|
|
13
|
+
C -->|extends| D[GreatGrandParentInterface]
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
**Author** John Doe
|
|
17
|
+
|
|
18
|
+
**Date** 2020-01-01
|
|
19
|
+
|
|
20
|
+
**See** [SampleEnum](../sample-enums/SampleEnum.md)
|
|
21
|
+
|
|
22
|
+
**See** [ReferencedEnum](ReferencedEnum.md)
|
|
23
|
+
|
|
24
|
+
## Example
|
|
25
|
+
```apex
|
|
26
|
+
SampleInterface sampleInterface = new SampleInterface();
|
|
27
|
+
sampleInterface.sampleMethod();
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
**Extends**
|
|
31
|
+
[ParentInterface](ParentInterface.md)
|
|
32
|
+
|
|
33
|
+
## Methods
|
|
34
|
+
### `sampleMethod()`
|
|
35
|
+
|
|
36
|
+
`NAMESPACEACCESSIBLE`
|
|
37
|
+
|
|
38
|
+
This is a sample method
|
|
39
|
+
|
|
40
|
+
**Custom Tag**
|
|
41
|
+
|
|
42
|
+
This is a custom tag
|
|
43
|
+
|
|
44
|
+
**Another Custom Tag**
|
|
45
|
+
|
|
46
|
+
This is another custom tag
|
|
47
|
+
|
|
48
|
+
**Mermaid**
|
|
49
|
+
|
|
50
|
+
graph TD
|
|
51
|
+
A[SampleInterface] -->|extends| B[ParentInterface]
|
|
52
|
+
B -->|extends| C[GrandParentInterface]
|
|
53
|
+
C -->|extends| D[GreatGrandParentInterface]
|
|
54
|
+
|
|
55
|
+
#### Signature
|
|
56
|
+
```apex
|
|
57
|
+
public String sampleMethod()
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
#### Return Type
|
|
61
|
+
**String**
|
|
62
|
+
|
|
63
|
+
Some return value
|
|
64
|
+
|
|
65
|
+
#### Throws
|
|
66
|
+
[SampleException](SampleException.md): This is a sample exception
|
|
67
|
+
|
|
68
|
+
AnotherSampleException: This is another sample exception
|
|
69
|
+
|
|
70
|
+
#### Example
|
|
71
|
+
SampleInterface sampleInterface = new SampleInterface();
|
|
72
|
+
sampleInterface.sampleMethod();
|
|
73
|
+
|
|
74
|
+
---
|
|
75
|
+
|
|
76
|
+
### `sampleMethodWithParams(param1, param2, theEnum)`
|
|
77
|
+
|
|
78
|
+
`NAMESPACEACCESSIBLE`
|
|
79
|
+
`DEPRECATED`
|
|
80
|
+
|
|
81
|
+
This is a sample method with parameters
|
|
82
|
+
Sometimes it won't be possible to find a NonExistent link.
|
|
83
|
+
|
|
84
|
+
#### Signature
|
|
85
|
+
```apex
|
|
86
|
+
public SampleEnum sampleMethodWithParams(String param1, Integer param2, SampleEnum theEnum)
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
#### Parameters
|
|
90
|
+
| Name | Type | Description |
|
|
91
|
+
|------|------|-------------|
|
|
92
|
+
| param1 | String | This is the first parameter |
|
|
93
|
+
| param2 | Integer | This is the second parameter |
|
|
94
|
+
| theEnum | [SampleEnum](../sample-enums/SampleEnum.md) | This is an enum parameter |
|
|
95
|
+
|
|
96
|
+
#### Return Type
|
|
97
|
+
**[SampleEnum](../sample-enums/SampleEnum.md)**
|
|
98
|
+
|
|
99
|
+
Some return value
|
|
100
|
+
|
|
101
|
+
---
|
|
102
|
+
|
|
103
|
+
### `sampleParentMethod()`
|
|
104
|
+
|
|
105
|
+
*Inherited*
|
|
106
|
+
|
|
107
|
+
#### Signature
|
|
108
|
+
```apex
|
|
109
|
+
public void sampleParentMethod()
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
#### Return Type
|
|
113
|
+
**void**
|
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
# Url Class
|
|
2
|
+
|
|
3
|
+
Represents a uniform resource locator (URL) and provides access to parts of the URL.
|
|
4
|
+
Enables access to the base URL used to access your Salesforce org.
|
|
5
|
+
|
|
6
|
+
## Usage
|
|
7
|
+
Use the methods of the `System.URL` class to create links to objects in your organization. Such objects can be files, images,
|
|
8
|
+
logos, or records that you want to include in external emails, in activities, or in Chatter posts. For example, you can create
|
|
9
|
+
a link to a file uploaded as an attachment to a Chatter post by concatenating the Salesforce base URL with the file ID:
|
|
10
|
+
|
|
11
|
+
```apex
|
|
12
|
+
// Get a file uploaded through Chatter.
|
|
13
|
+
ContentDocument doc = [SELECT Id FROM ContentDocument
|
|
14
|
+
WHERE Title = 'myfile'];
|
|
15
|
+
// Create a link to the file.
|
|
16
|
+
String fullFileURL = URL.getOrgDomainURL().toExternalForm() +
|
|
17
|
+
'/' + doc.id;
|
|
18
|
+
system.debug(fullFileURL);
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
The following example creates a link to a Salesforce record. The full URL is created by concatenating the Salesforce base
|
|
23
|
+
URL with the record ID.
|
|
24
|
+
|
|
25
|
+
```ape
|
|
26
|
+
Account acct = [SELECT Id FROM Account WHERE Name = 'Acme' LIMIT 1];
|
|
27
|
+
String fullRecordURL = URL.getOrgDomainURL().toExternalForm() + '/' + acct.Id;
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
## Example
|
|
32
|
+
In this example, the base URL and the full request URL of the current Salesforce server instance are retrieved. Next, a URL
|
|
33
|
+
pointing to a specific account object is created. Finally, components of the base and full URL are obtained. This example
|
|
34
|
+
prints out all the results to the debug log output.
|
|
35
|
+
|
|
36
|
+
```apex
|
|
37
|
+
// Create a new account called Acme that we will create a link for later.
|
|
38
|
+
Account myAccount = new Account(Name='Acme');
|
|
39
|
+
insert myAccount;
|
|
40
|
+
|
|
41
|
+
// Get the base URL.
|
|
42
|
+
String sfdcBaseURL = URL.getOrgDomainURL().toExternalForm();
|
|
43
|
+
System.debug('Base URL: ' + sfdcBaseURL );
|
|
44
|
+
|
|
45
|
+
// Get the URL for the current request.
|
|
46
|
+
String currentRequestURL = URL.getCurrentRequestUrl().toExternalForm();
|
|
47
|
+
System.debug('Current request URL: ' + currentRequestURL);
|
|
48
|
+
|
|
49
|
+
// Create the account URL from the base URL.
|
|
50
|
+
String accountURL = URL.getOrgDomainURL().toExternalForm() +
|
|
51
|
+
'/' + myAccount.Id;
|
|
52
|
+
System.debug('URL of a particular account: ' + accountURL);
|
|
53
|
+
|
|
54
|
+
// Get some parts of the base URL.
|
|
55
|
+
System.debug('Host: ' + URL.getOrgDomainURL().getHost());
|
|
56
|
+
System.debug('Protocol: ' + URL.getOrgDomainURL().getProtocol());
|
|
57
|
+
|
|
58
|
+
// Get the query string of the current request.
|
|
59
|
+
System.debug('Query: ' + URL.getCurrentRequestUrl().getQuery());
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
## Version Behavior Changes
|
|
64
|
+
In API version 41.0 and later, Apex URL objects are represented by the java.net.URI type, not the java.net.URL type.
|
|
65
|
+
The API version in which the URL object was instantiated determines the behavior of subsequent method calls to the
|
|
66
|
+
specific instance. Salesforce strongly encourages you to use API 41.0 and later versions for fully RFC-compliant URL
|
|
67
|
+
parsing that includes proper handling of edge cases of complex URL structures. API 41.0 and later versions also enforce
|
|
68
|
+
that inputs are valid, RFC-compliant URL or URI strings.
|
|
69
|
+
|
|
70
|
+
* [URL Constructors](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_url.htm#apex_System_URL_constructors)
|
|
71
|
+
* [URL Methods](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_url.htm#apex_System_URL_methods)
|
|
72
|
+
|
|
73
|
+
**See Also**
|
|
74
|
+
* [URL Class](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_url.htm)
|
|
75
|
+
|
|
76
|
+
## Constructors
|
|
77
|
+
### `Url(spec)`
|
|
78
|
+
|
|
79
|
+
Creates a new instance of the URL class using the specified string representation of the URL.
|
|
80
|
+
|
|
81
|
+
#### Signature
|
|
82
|
+
```apex
|
|
83
|
+
global Url(String spec)
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
#### Parameters
|
|
87
|
+
| Name | Type | Description |
|
|
88
|
+
|------|------|-------------|
|
|
89
|
+
| spec | String | The string to parse as a URL. |
|
|
90
|
+
|
|
91
|
+
---
|
|
92
|
+
|
|
93
|
+
### `Url(context, spec)`
|
|
94
|
+
|
|
95
|
+
Creates a new instance of the URL class by parsing the specified spec within the specified context.
|
|
96
|
+
|
|
97
|
+
**Usage**
|
|
98
|
+
|
|
99
|
+
The new URL is created from the given context URL and the spec argument as described in RFC2396 "Uniform Resource Identifiers : Generic * Syntax" :
|
|
100
|
+
```xml
|
|
101
|
+
<scheme>://<authority><path>?<query>#<fragment>
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
For more information about the arguments of this constructor, see the corresponding URL(java.net.URL, java.lang.String) constructor for Java.
|
|
106
|
+
|
|
107
|
+
#### Signature
|
|
108
|
+
```apex
|
|
109
|
+
global Url(Url context, String spec)
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
#### Parameters
|
|
113
|
+
| Name | Type | Description |
|
|
114
|
+
|------|------|-------------|
|
|
115
|
+
| context | [Url](Url.md) | The context in which to parse the specification. |
|
|
116
|
+
| spec | String | The string to parse as a URL. |
|
|
117
|
+
|
|
118
|
+
---
|
|
119
|
+
|
|
120
|
+
### `Url(protocol, host, file)`
|
|
121
|
+
|
|
122
|
+
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.
|
|
123
|
+
|
|
124
|
+
#### Signature
|
|
125
|
+
```apex
|
|
126
|
+
global Url(String protocol, String host, String file)
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
#### Parameters
|
|
130
|
+
| Name | Type | Description |
|
|
131
|
+
|------|------|-------------|
|
|
132
|
+
| protocol | String | The protocol name for this URL. |
|
|
133
|
+
| host | String | The host name for this URL. |
|
|
134
|
+
| file | String | The file name for this URL. |
|
|
135
|
+
|
|
136
|
+
---
|
|
137
|
+
|
|
138
|
+
### `Url(protocol, host, port, file)`
|
|
139
|
+
|
|
140
|
+
Creates a new instance of the URL class using the specified protocol, host, port number, and file on the host.
|
|
141
|
+
|
|
142
|
+
#### Signature
|
|
143
|
+
```apex
|
|
144
|
+
global Url(String protocol, String host, Integer port, String file)
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
#### Parameters
|
|
148
|
+
| Name | Type | Description |
|
|
149
|
+
|------|------|-------------|
|
|
150
|
+
| protocol | String | The protocol name for this URL. |
|
|
151
|
+
| host | String | The host name for this URL. |
|
|
152
|
+
| port | Integer | The port number for this URL. |
|
|
153
|
+
| file | String | The file name for this URL. |
|
|
154
|
+
|
|
155
|
+
## Methods
|
|
156
|
+
### `getAuthority()`
|
|
157
|
+
|
|
158
|
+
Returns the authority portion of the current URL.
|
|
159
|
+
|
|
160
|
+
#### Signature
|
|
161
|
+
```apex
|
|
162
|
+
global String getAuthority()
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
#### Return Type
|
|
166
|
+
**String**
|
|
167
|
+
|
|
168
|
+
The authority portion of the current URL.
|
|
169
|
+
|
|
170
|
+
---
|
|
171
|
+
|
|
172
|
+
### `getCurrentRequestUrl()`
|
|
173
|
+
|
|
174
|
+
Returns the URL of an entire request on a Salesforce instance.
|
|
175
|
+
|
|
176
|
+
**Usage**
|
|
177
|
+
|
|
178
|
+
An example of a URL for an entire request is https://yourInstance.salesforce.com/apex/myVfPage.apexp.
|
|
179
|
+
|
|
180
|
+
#### Signature
|
|
181
|
+
```apex
|
|
182
|
+
global static Url getCurrentRequestUrl()
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
#### Return Type
|
|
186
|
+
**[Url](Url.md)**
|
|
187
|
+
|
|
188
|
+
The URL of the entire request.
|
|
189
|
+
|
|
190
|
+
---
|
|
191
|
+
|
|
192
|
+
### `getDefPort()`
|
|
193
|
+
|
|
194
|
+
Returns the default port number of the protocol associated with the current URL.
|
|
195
|
+
|
|
196
|
+
**Usage**
|
|
197
|
+
|
|
198
|
+
Returns -1 if the URL scheme or the stream protocol handler for the URL doesn't define a default port number.
|
|
199
|
+
|
|
200
|
+
#### Signature
|
|
201
|
+
```apex
|
|
202
|
+
global Integer getDefPort()
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
#### Return Type
|
|
206
|
+
**Integer**
|
|
207
|
+
|
|
208
|
+
The default port number of the protocol associated with the current URL.
|
|
209
|
+
|
|
210
|
+
---
|
|
211
|
+
|
|
212
|
+
### `getFile()`
|
|
213
|
+
|
|
214
|
+
Returns the file name of the current URL.
|
|
215
|
+
|
|
216
|
+
#### Signature
|
|
217
|
+
```apex
|
|
218
|
+
global String getFile()
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
#### Return Type
|
|
222
|
+
**String**
|
|
223
|
+
|
|
224
|
+
The file name of the current URL.
|
|
225
|
+
|
|
226
|
+
---
|
|
227
|
+
|
|
228
|
+
### `getFileFieldURL(entityId, fieldName)`
|
|
229
|
+
|
|
230
|
+
Returns the download URL for a file attachment.
|
|
231
|
+
|
|
232
|
+
#### Signature
|
|
233
|
+
```apex
|
|
234
|
+
global static String getFileFieldURL(String entityId, String fieldName)
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
#### Parameters
|
|
238
|
+
| Name | Type | Description |
|
|
239
|
+
|------|------|-------------|
|
|
240
|
+
| entityId | String | Specifies the ID of the entity that holds the file data. |
|
|
241
|
+
| fieldName | String | Specifies the API name of a file field component, such as `AttachmentBody` . |
|
|
242
|
+
|
|
243
|
+
#### Return Type
|
|
244
|
+
**String**
|
|
245
|
+
|
|
246
|
+
The download URL for the file attachment.
|
|
247
|
+
|
|
248
|
+
#### Example
|
|
249
|
+
String fileURL =
|
|
250
|
+
URL.getFileFieldURL(
|
|
251
|
+
'087000000000123' ,
|
|
252
|
+
'AttachmentBody');
|
|
253
|
+
|
|
254
|
+
---
|
|
255
|
+
|
|
256
|
+
### `getHost()`
|
|
257
|
+
|
|
258
|
+
Returns the host name of the current URL.
|
|
259
|
+
|
|
260
|
+
#### Signature
|
|
261
|
+
```apex
|
|
262
|
+
global String getHost()
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
#### Return Type
|
|
266
|
+
**String**
|
|
267
|
+
|
|
268
|
+
The host name of the current URL.
|
|
269
|
+
|
|
270
|
+
---
|
|
271
|
+
|
|
272
|
+
### `getOrgDomainUrl()`
|
|
273
|
+
|
|
274
|
+
Returns the canonical URL for your org. For example, https://MyDomainName.my.salesforce.com.
|
|
275
|
+
|
|
276
|
+
**Usage**
|
|
277
|
+
|
|
278
|
+
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.
|
|
279
|
+
|
|
280
|
+
`getOrgDomainUrl()` can access the domain URL only for the org in which the Apex code is running.
|
|
281
|
+
|
|
282
|
+
You don't need a RemoteSiteSetting for your org to interact with the Salesforce APIs using domain URLs retrieved with this method.
|
|
283
|
+
|
|
284
|
+
**See Also**
|
|
285
|
+
|
|
286
|
+
* [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)
|
|
287
|
+
|
|
288
|
+
#### Signature
|
|
289
|
+
```apex
|
|
290
|
+
global static Url getOrgDomainUrl()
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
#### Return Type
|
|
294
|
+
**[Url](Url.md)**
|
|
295
|
+
|
|
296
|
+
getOrgDomainUrl() always returns the login URL for your org, regardless of context. Use that URL when making API calls to your org.
|
|
297
|
+
|
|
298
|
+
#### Example
|
|
299
|
+
This example uses the Salesforce REST API to get organization limit values. For information on limits, see Limits in the REST API Developer Guide.
|
|
300
|
+
```apex
|
|
301
|
+
Http h = new Http();
|
|
302
|
+
HttpRequest req = new HttpRequest();
|
|
303
|
+
req.setEndpoint(Url.getOrgDomainUrl().toExternalForm()
|
|
304
|
+
+ '/services/data/v44.0/limits');
|
|
305
|
+
req.setMethod('GET');
|
|
306
|
+
req.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionId());
|
|
307
|
+
HttpResponse res = h.send(req);
|
|
308
|
+
```
|