Skip to content

Commit 4623840

Browse files
committed
Merge branch 'main' into prerelease/beta
2 parents 2f3cf92 + 84cf696 commit 4623840

File tree

8 files changed

+219
-297
lines changed

8 files changed

+219
-297
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# [4.6.0](https://github.com/salesforcecli/plugin-org/compare/4.5.10...4.6.0) (2024-09-25)
2+
3+
### Features
4+
5+
- **sbx:** support new `Name` fields in def. file ([#1221](https://github.com/salesforcecli/plugin-org/issues/1221)) ([7a64c03](https://github.com/salesforcecli/plugin-org/commit/7a64c03ec2e9e17e212f7c3643fa264e5f1d05e0))
6+
17
## [4.5.10](https://github.com/salesforcecli/plugin-org/compare/4.5.9...4.5.10) (2024-09-22)
28

39
### Bug Fixes

README.md

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -99,20 +99,29 @@ the [SandboxNuts](https://github.com/salesforcecli/plugin-org/actions/workflows/
9999

100100
<!-- commands -->
101101

102-
- [`sf org create sandbox`](#sf-org-create-sandbox)
103-
- [`sf org create scratch`](#sf-org-create-scratch)
104-
- [`sf org delete sandbox`](#sf-org-delete-sandbox)
105-
- [`sf org delete scratch`](#sf-org-delete-scratch)
106-
- [`sf org disable tracking`](#sf-org-disable-tracking)
107-
- [`sf org display`](#sf-org-display)
108-
- [`sf org enable tracking`](#sf-org-enable-tracking)
109-
- [`sf org list`](#sf-org-list)
110-
- [`sf org list metadata`](#sf-org-list-metadata)
111-
- [`sf org list metadata-types`](#sf-org-list-metadata-types)
112-
- [`sf org open`](#sf-org-open)
113-
- [`sf org refresh sandbox`](#sf-org-refresh-sandbox)
114-
- [`sf org resume sandbox`](#sf-org-resume-sandbox)
115-
- [`sf org resume scratch`](#sf-org-resume-scratch)
102+
- [plugin-org](#plugin-org)
103+
- [About Salesforce CLI plugins](#about-salesforce-cli-plugins)
104+
- [Install](#install)
105+
- [Issues](#issues)
106+
- [Contributing](#contributing)
107+
- [CLA](#cla)
108+
- [Build](#build)
109+
- [Sandbox NUTs](#sandbox-nuts)
110+
- [Commands](#commands)
111+
- [`sf org create sandbox`](#sf-org-create-sandbox)
112+
- [`sf org create scratch`](#sf-org-create-scratch)
113+
- [`sf org delete sandbox`](#sf-org-delete-sandbox)
114+
- [`sf org delete scratch`](#sf-org-delete-scratch)
115+
- [`sf org disable tracking`](#sf-org-disable-tracking)
116+
- [`sf org display`](#sf-org-display)
117+
- [`sf org enable tracking`](#sf-org-enable-tracking)
118+
- [`sf org list`](#sf-org-list)
119+
- [`sf org list metadata`](#sf-org-list-metadata)
120+
- [`sf org list metadata-types`](#sf-org-list-metadata-types)
121+
- [`sf org open`](#sf-org-open)
122+
- [`sf org refresh sandbox`](#sf-org-refresh-sandbox)
123+
- [`sf org resume sandbox`](#sf-org-resume-sandbox)
124+
- [`sf org resume scratch`](#sf-org-resume-scratch)
116125

117126
## `sf org create sandbox`
118127

@@ -229,7 +238,7 @@ FLAG DESCRIPTIONS
229238
sandbox.
230239
```
231240

232-
_See code: [src/commands/org/create/sandbox.ts](https://github.com/salesforcecli/plugin-org/blob/4.5.11-dev.0/src/commands/org/create/sandbox.ts)_
241+
_See code: [src/commands/org/create/sandbox.ts](https://github.com/salesforcecli/plugin-org/blob/4.6.0/src/commands/org/create/sandbox.ts)_
233242

234243
## `sf org create scratch`
235244

@@ -383,7 +392,7 @@ FLAG DESCRIPTIONS
383392
Omit this flag to have Salesforce generate a unique username for your org.
384393
```
385394

386-
_See code: [src/commands/org/create/scratch.ts](https://github.com/salesforcecli/plugin-org/blob/4.5.11-dev.0/src/commands/org/create/scratch.ts)_
395+
_See code: [src/commands/org/create/scratch.ts](https://github.com/salesforcecli/plugin-org/blob/4.6.0/src/commands/org/create/scratch.ts)_
387396

388397
## `sf org delete sandbox`
389398

@@ -429,7 +438,7 @@ EXAMPLES
429438
$ sf org delete sandbox --target-org my-sandbox --no-prompt
430439
```
431440

432-
_See code: [src/commands/org/delete/sandbox.ts](https://github.com/salesforcecli/plugin-org/blob/4.5.11-dev.0/src/commands/org/delete/sandbox.ts)_
441+
_See code: [src/commands/org/delete/sandbox.ts](https://github.com/salesforcecli/plugin-org/blob/4.6.0/src/commands/org/delete/sandbox.ts)_
433442

434443
## `sf org delete scratch`
435444

@@ -473,7 +482,7 @@ EXAMPLES
473482
$ sf org delete scratch --target-org my-scratch-org --no-prompt
474483
```
475484

476-
_See code: [src/commands/org/delete/scratch.ts](https://github.com/salesforcecli/plugin-org/blob/4.5.11-dev.0/src/commands/org/delete/scratch.ts)_
485+
_See code: [src/commands/org/delete/scratch.ts](https://github.com/salesforcecli/plugin-org/blob/4.6.0/src/commands/org/delete/scratch.ts)_
477486

478487
## `sf org disable tracking`
479488

@@ -512,7 +521,7 @@ EXAMPLES
512521
$ sf org disable tracking
513522
```
514523

515-
_See code: [src/commands/org/disable/tracking.ts](https://github.com/salesforcecli/plugin-org/blob/4.5.11-dev.0/src/commands/org/disable/tracking.ts)_
524+
_See code: [src/commands/org/disable/tracking.ts](https://github.com/salesforcecli/plugin-org/blob/4.6.0/src/commands/org/disable/tracking.ts)_
516525

517526
## `sf org display`
518527

@@ -557,7 +566,7 @@ EXAMPLES
557566
$ sf org display --target-org TestOrg1 --verbose
558567
```
559568

560-
_See code: [src/commands/org/display.ts](https://github.com/salesforcecli/plugin-org/blob/4.5.11-dev.0/src/commands/org/display.ts)_
569+
_See code: [src/commands/org/display.ts](https://github.com/salesforcecli/plugin-org/blob/4.6.0/src/commands/org/display.ts)_
561570

562571
## `sf org enable tracking`
563572

@@ -599,7 +608,7 @@ EXAMPLES
599608
$ sf org enable tracking
600609
```
601610

602-
_See code: [src/commands/org/enable/tracking.ts](https://github.com/salesforcecli/plugin-org/blob/4.5.11-dev.0/src/commands/org/enable/tracking.ts)_
611+
_See code: [src/commands/org/enable/tracking.ts](https://github.com/salesforcecli/plugin-org/blob/4.6.0/src/commands/org/enable/tracking.ts)_
603612

604613
## `sf org list`
605614

@@ -638,7 +647,7 @@ EXAMPLES
638647
$ sf org list --clean
639648
```
640649

641-
_See code: [src/commands/org/list.ts](https://github.com/salesforcecli/plugin-org/blob/4.5.11-dev.0/src/commands/org/list.ts)_
650+
_See code: [src/commands/org/list.ts](https://github.com/salesforcecli/plugin-org/blob/4.6.0/src/commands/org/list.ts)_
642651

643652
## `sf org list metadata`
644653

@@ -705,7 +714,7 @@ FLAG DESCRIPTIONS
705714
Examples of metadata types that use folders are Dashboard, Document, EmailTemplate, and Report.
706715
```
707716

708-
_See code: [src/commands/org/list/metadata.ts](https://github.com/salesforcecli/plugin-org/blob/4.5.11-dev.0/src/commands/org/list/metadata.ts)_
717+
_See code: [src/commands/org/list/metadata.ts](https://github.com/salesforcecli/plugin-org/blob/4.6.0/src/commands/org/list/metadata.ts)_
709718

710719
## `sf org list metadata-types`
711720

@@ -760,7 +769,7 @@ FLAG DESCRIPTIONS
760769
Override the api version used for api requests made by this command
761770
```
762771

763-
_See code: [src/commands/org/list/metadata-types.ts](https://github.com/salesforcecli/plugin-org/blob/4.5.11-dev.0/src/commands/org/list/metadata-types.ts)_
772+
_See code: [src/commands/org/list/metadata-types.ts](https://github.com/salesforcecli/plugin-org/blob/4.6.0/src/commands/org/list/metadata-types.ts)_
764773

765774
## `sf org open`
766775

@@ -832,7 +841,7 @@ EXAMPLES
832841
$ sf org open --source-file force-app/main/default/flows/Hello.flow-meta.xml
833842
```
834843

835-
_See code: [src/commands/org/open.ts](https://github.com/salesforcecli/plugin-org/blob/4.5.11-dev.0/src/commands/org/open.ts)_
844+
_See code: [src/commands/org/open.ts](https://github.com/salesforcecli/plugin-org/blob/4.6.0/src/commands/org/open.ts)_
836845

837846
## `sf org refresh sandbox`
838847

@@ -909,7 +918,7 @@ FLAG DESCRIPTIONS
909918
By default, a sandbox auto-activates after a refresh. Use this flag to control sandbox activation manually.
910919
```
911920

912-
_See code: [src/commands/org/refresh/sandbox.ts](https://github.com/salesforcecli/plugin-org/blob/4.5.11-dev.0/src/commands/org/refresh/sandbox.ts)_
921+
_See code: [src/commands/org/refresh/sandbox.ts](https://github.com/salesforcecli/plugin-org/blob/4.6.0/src/commands/org/refresh/sandbox.ts)_
913922

914923
## `sf org resume sandbox`
915924

@@ -972,7 +981,7 @@ FLAG DESCRIPTIONS
972981
returns the job ID. To resume checking the sandbox creation, rerun this command.
973982
```
974983

975-
_See code: [src/commands/org/resume/sandbox.ts](https://github.com/salesforcecli/plugin-org/blob/4.5.11-dev.0/src/commands/org/resume/sandbox.ts)_
984+
_See code: [src/commands/org/resume/sandbox.ts](https://github.com/salesforcecli/plugin-org/blob/4.6.0/src/commands/org/resume/sandbox.ts)_
976985

977986
## `sf org resume scratch`
978987

@@ -1019,6 +1028,6 @@ FLAG DESCRIPTIONS
10191028
The job ID is valid for 24 hours after you start the scratch org creation.
10201029
```
10211030

1022-
_See code: [src/commands/org/resume/scratch.ts](https://github.com/salesforcecli/plugin-org/blob/4.5.11-dev.0/src/commands/org/resume/scratch.ts)_
1031+
_See code: [src/commands/org/resume/scratch.ts](https://github.com/salesforcecli/plugin-org/blob/4.6.0/src/commands/org/resume/scratch.ts)_
10231032

10241033
<!-- commandsstop -->

messages/clone.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,19 @@ Specify a value for %s in a definition file or on the command line.
55
# missingSourceSandboxNameAction
66

77
To indicate which sandbox org you want to clone, specify %s in a definition file or as a command line argument.
8+
9+
# error.bothApexClassIdAndNameProvided
10+
11+
You can't specify both `apexClassId` and `apexClassName` in the definition file at the same time.
12+
13+
# error.bothUserGroupIdAndNameProvided
14+
15+
You can't specify both `ActivationUserGroupId` and `ActivationUserGroupName` in the definition file at the same time.
16+
17+
# error.userGroupQueryFailed
18+
19+
Unable to find the ID of the activation user group "%s" that's defined in the definition file.
20+
21+
# error.apexClassQueryFailed
22+
23+
Unable to find the ID of the Apex class "%s" that's defined in the definition file.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
22
"name": "@salesforce/plugin-org",
33
"description": "Commands to interact with Salesforce orgs",
4-
"version": "4.5.11-dev.0",
4+
"version": "4.6.0",
55
"author": "Salesforce",
66
"bugs": "https://github.com/forcedotcom/cli/issues",
77
"dependencies": {
88
"@oclif/core": "^4.0.16",
9-
"@oclif/multi-stage-output": "^0.5.5",
10-
"@salesforce/core": "^8.5.5",
9+
"@oclif/multi-stage-output": "^0.7.0",
10+
"@salesforce/core": "^8.6.1",
1111
"@salesforce/kit": "^3.2.3",
1212
"@salesforce/sf-plugins-core": "^11.3.7",
1313
"@salesforce/source-deploy-retrieve": "^12.7.1",

src/commands/org/create/sandbox.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,31 @@ export default class CreateSandbox extends SandboxCommandBase<SandboxCommandResp
135135
const { sandboxReq } = !this.flags.clone
136136
? await requestFunctions.createSandboxRequest(false, this.flags['definition-file'], undefined, requestOptions)
137137
: await requestFunctions.createSandboxRequest(true, this.flags['definition-file'], undefined, requestOptions);
138+
139+
let apexId: string | undefined;
140+
let groupId: string | undefined;
141+
142+
// Determine which value to use
143+
if (sandboxReq.ApexClassName) {
144+
apexId = await requestFunctions.getApexClassIdByName(
145+
this.flags['target-org'].getConnection(),
146+
sandboxReq.ApexClassName
147+
); // convert name to ID
148+
delete sandboxReq.ApexClassName;
149+
}
150+
151+
if (sandboxReq.ActivationUserGroupName) {
152+
groupId = await requestFunctions.getUserGroupIdByName(
153+
this.flags['target-org'].getConnection(),
154+
sandboxReq.ActivationUserGroupName
155+
);
156+
delete sandboxReq.ActivationUserGroupName;
157+
}
138158
return {
139159
...sandboxReq,
140160
...(this.flags.clone ? { SourceId: await this.getSourceId() } : {}),
161+
...(apexId ? { ApexClassId: apexId } : {}),
162+
...(groupId ? { ActivationUserGroupId: groupId } : {}),
141163
};
142164
}
143165

src/commands/org/refresh/sandbox.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,28 @@ export default class RefreshSandbox extends SandboxCommandBase<SandboxCommandRes
186186
throw messages.createError('error.NoSandboxName');
187187
}
188188

189+
let apexId: string | undefined;
190+
let groupId: string | undefined;
191+
192+
if (defFileContent.ApexClassName) {
193+
apexId = await requestFunctions.getApexClassIdByName(
194+
this.flags['target-org'].getConnection(),
195+
defFileContent.ApexClassName
196+
); // convert name to ID
197+
delete defFileContent.ApexClassName;
198+
}
199+
200+
if (defFileContent.ActivationUserGroupName) {
201+
groupId = await requestFunctions.getUserGroupIdByName(
202+
this.flags['target-org'].getConnection(),
203+
defFileContent.ActivationUserGroupName
204+
);
205+
delete defFileContent.ActivationUserGroupName;
206+
}
189207
// Warn if sandbox name is in `--name` and `--definition-file` flags and they differ.
190208
if (defFileContent?.SandboxName && sbxName && sbxName !== defFileContent?.SandboxName) {
191209
this.warn(messages.createWarning('warning.ConflictingSandboxNames', [sbxName, defFileContent?.SandboxName]));
192210
}
193-
194211
sbxName ??= defFileContent.SandboxName as string; // The code above ensures a value for sbxName
195212

196213
const prodOrg = this.flags['target-org'];
@@ -213,6 +230,8 @@ export default class RefreshSandbox extends SandboxCommandBase<SandboxCommandRes
213230
sandboxInfo = Object.assign(sandboxInfo, defFileContent, {
214231
SandboxName: sbxName,
215232
AutoActivate: !this.flags['no-auto-activate'],
233+
...(apexId ? { ApexClassId: apexId } : {}),
234+
...(groupId ? { ActivationUserGroupId: groupId } : {}),
216235
});
217236

218237
return sandboxInfo;

src/shared/sandboxRequest.ts

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77
import fs from 'node:fs';
88

9-
import { Logger, SandboxInfo, SandboxRequest, Messages, SfError, Lifecycle } from '@salesforce/core';
9+
import { Logger, SandboxInfo, SandboxRequest, Messages, SfError, Lifecycle, Connection } from '@salesforce/core';
1010
import { lowerToUpper } from './utils.js';
1111
import { SandboxLicenseType } from './orgTypes.js';
1212

@@ -22,24 +22,46 @@ export const generateSboxName = async (): Promise<string> => {
2222
};
2323

2424
// Reads the sandbox definition file and converts properties to CapCase.
25-
export function readSandboxDefFile(defFile: string): Partial<SandboxInfo> {
25+
export function readSandboxDefFile(
26+
defFile: string
27+
): Partial<SandboxInfo & { ApexClassName?: string; ActivationUserGroupName?: string }> {
2628
const fileContent = fs.readFileSync(defFile, 'utf-8');
27-
const parsedContent = JSON.parse(fileContent) as Record<string, unknown>;
28-
return lowerToUpper(parsedContent) as Partial<SandboxInfo>;
29+
const parsedContent = lowerToUpper(JSON.parse(fileContent) as Record<string, unknown>);
30+
31+
// validate input
32+
if (parsedContent.ApexClassName && parsedContent.ApexClassId) {
33+
throw cloneMessages.createError('error.bothApexClassIdAndNameProvided');
34+
}
35+
36+
if (parsedContent.ActivationUserGroupId && parsedContent.ActivationUserGroupName) {
37+
throw cloneMessages.createError('error.bothUserGroupIdAndNameProvided');
38+
}
39+
return parsedContent as Partial<SandboxInfo>;
2940
}
3041

3142
export async function createSandboxRequest(
3243
isClone: true,
3344
definitionFile: string | undefined,
3445
logger?: Logger | undefined,
3546
properties?: Record<string, string | undefined>
36-
): Promise<{ sandboxReq: SandboxRequest; srcSandboxName: string }>;
47+
): Promise<{
48+
sandboxReq: SandboxRequest & {
49+
ApexClassName: string | undefined;
50+
ActivationUserGroupName: string | undefined;
51+
};
52+
srcSandboxName: string;
53+
}>;
3754
export async function createSandboxRequest(
3855
isClone: false,
3956
definitionFile: string | undefined,
4057
logger?: Logger | undefined,
4158
properties?: Record<string, string | undefined>
42-
): Promise<{ sandboxReq: SandboxRequest }>;
59+
): Promise<{
60+
sandboxReq: SandboxRequest & {
61+
ApexClassName: string | undefined;
62+
ActivationUserGroupName: string | undefined;
63+
};
64+
}>;
4365
export async function createSandboxRequest(
4466
isClone = false,
4567
definitionFile: string | undefined,
@@ -52,6 +74,7 @@ export async function createSandboxRequest(
5274
logger.debug('Varargs: %s ', properties);
5375

5476
const sandboxDefFileContents = definitionFile ? readSandboxDefFile(definitionFile) : {};
77+
5578
const capitalizedVarArgs = properties ? lowerToUpper(properties) : {};
5679

5780
// varargs override file input
@@ -83,9 +106,26 @@ export async function createSandboxRequest(
83106
return { sandboxReq };
84107
}
85108
}
86-
109+
export async function getApexClassIdByName(conn: Connection, className: string): Promise<string | undefined> {
110+
try {
111+
const result = (await conn.singleRecordQuery(`SELECT Id FROM ApexClass WHERE Name = '${className}'`)).Id;
112+
return result;
113+
} catch (err) {
114+
throw cloneMessages.createError('error.apexClassQueryFailed', [className], [], err as Error);
115+
}
116+
}
117+
export async function getUserGroupIdByName(conn: Connection, groupName: string): Promise<string | undefined> {
118+
try {
119+
const result = (await conn.singleRecordQuery(`SELECT id FROM Group WHERE NAME = '${groupName}'`)).Id;
120+
return result;
121+
} catch (err) {
122+
throw cloneMessages.createError('error.userGroupQueryFailed', [groupName], [], err as Error);
123+
}
124+
}
87125
export default {
88126
createSandboxRequest,
89127
generateSboxName,
90128
readSandboxDefFile,
129+
getApexClassIdByName,
130+
getUserGroupIdByName,
91131
};

0 commit comments

Comments
 (0)