Skip to content

Commit fe66b95

Browse files
chore: remove --username flag
1 parent dc0c71e commit fe66b95

4 files changed

Lines changed: 16 additions & 79 deletions

File tree

command-snapshot.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"command": "org:create:agent-user",
55
"flagAliases": [],
66
"flagChars": ["o"],
7-
"flags": ["api-version", "base-username", "first-name", "flags-dir", "json", "last-name", "target-org", "username"],
7+
"flags": ["api-version", "base-username", "first-name", "flags-dir", "json", "last-name", "target-org"],
88
"plugin": "@salesforce/plugin-org"
99
},
1010
{

messages/create_agent_user.md

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,32 @@
11
# summary
22

3-
Create an agent user for use with Agentforce.
3+
Create a default_agent_user for use with Agentforce and agentscript.
44

55
# description
66

7-
Agent users are specialized user accounts designed to be used as default_agent_user in AgentScript. These users are automatically configured with the Einstein Agent User profile and required Agentforce permission sets.
7+
Agent users are specialized user accounts designed to be used as default_agent_user in AgentScript. These users are
8+
automatically configured with the Einstein Agent User profile and required Agentforce permission sets.
89

910
The command automatically:
1011

1112
- Checks that agent user licenses are available in your org
12-
- Generates a globally unique username (or uses the one you specify)
13+
- Generates a globally unique username with a GUID for uniqueness
1314
- Creates the user with the Einstein Agent User profile
14-
- Assigns required permission sets: AgentforceServiceAgentBase, AgentforceServiceAgentUser, EinsteinGPTPromptTemplateUser
15+
- Assigns required permission sets: AgentforceServiceAgentBase, AgentforceServiceAgentUser,
16+
EinsteinGPTPromptTemplateUser
1517
- Infers locale settings (timezone, language) from the current user
1618

1719
To assign additional permission sets after creation, use: sf org assign permset
1820

19-
The command performs comprehensive validation and provides clear error messages to help diagnose and resolve any issues during the creation process.
21+
The command performs comprehensive validation and provides clear error messages to help diagnose and resolve any issues
22+
during the creation process.
2023

2124
# examples
2225

2326
- Create an agent user with auto-generated username:
2427

2528
<%= config.bin %> <%= command.id %> --target-org myorg
2629

27-
- Create an agent user with a specific username:
28-
29-
<%= config.bin %> <%= command.id %> --target-org myorg --username service.agent@company.com
30-
3130
- Create an agent user with a base username pattern (GUID will be appended):
3231

3332
<%= config.bin %> <%= command.id %> --target-org myorg --base-username service-agent@corp.com
@@ -36,38 +35,22 @@ The command performs comprehensive validation and provides clear error messages
3635

3736
<%= config.bin %> <%= command.id %> --target-org myorg --first-name Service --last-name Agent
3837

39-
- Assign additional permission sets after creation:
40-
41-
<%= config.bin %> <%= command.id %> --target-org myorg
42-
<%= config.bin %> org assign permset --name CustomPermSet --target-org myorg --on-behalf-of <username>
43-
4438
# flags.target-org.summary
4539

4640
Username or alias of the target org where the agent user will be created.
4741

48-
# flags.username.summary
49-
50-
Username for the agent user. Auto-generated if not specified.
51-
52-
# flags.username.description
53-
54-
If you specify a username, it must be globally unique across the entire Salesforce universe (all orgs, sandboxes, and scratch orgs). The command will verify the username doesn't already exist before attempting to create the user.
55-
56-
If not specified (and no --base-username provided), the command automatically generates a unique username like: agent.user.a1b2c3d4e5f6@your-org-domain.com
57-
58-
This flag is mutually exclusive with --base-username.
59-
6042
# flags.base-username.summary
6143

6244
Base username pattern. A GUID will be appended to ensure global uniqueness.
6345

6446
# flags.base-username.description
6547

66-
Specify a base username in email format (e.g., service-agent@corp.com). The command will append a 12-character GUID to ensure the username is globally unique across all Salesforce orgs and sandboxes.
48+
Specify a base username in email format (e.g., service-agent@corp.com). The command will append a 12-character GUID to
49+
ensure the username is globally unique across all Salesforce orgs and sandboxes.
6750

6851
Example: "service-agent@corp.com" becomes "service-agent.a1b2c3d4e5f6@corp.com"
6952

70-
This flag is mutually exclusive with --username. If neither --username nor --base-username is specified, the command auto-generates: agent.user.<GUID>@your-org-domain.com
53+
If not specified, the command auto-generates: agent.user.<GUID>@your-org-domain.com
7154

7255
# flags.first-name.summary
7356

src/commands/org/create/agent-user.ts

Lines changed: 4 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,9 @@ export default class OrgCreateAgentUser extends SfCommand<AgentUserCreateRespons
3737
public static readonly flags = {
3838
'target-org': Flags.requiredOrg(),
3939
'api-version': Flags.orgApiVersion(),
40-
username: Flags.string({
41-
summary: messages.getMessage('flags.username.summary'),
42-
description: messages.getMessage('flags.username.description'),
43-
exclusive: ['base-username'],
44-
}),
4540
'base-username': Flags.string({
4641
summary: messages.getMessage('flags.base-username.summary'),
4742
description: messages.getMessage('flags.base-username.description'),
48-
exclusive: ['username'],
4943
}),
5044
'first-name': Flags.string({
5145
summary: messages.getMessage('flags.first-name.summary'),
@@ -62,7 +56,7 @@ export default class OrgCreateAgentUser extends SfCommand<AgentUserCreateRespons
6256
const connection = flags['target-org'].getConnection(flags['api-version']);
6357

6458
// Generate username
65-
const username = await this.generateUsername(connection, flags.username, flags['base-username']);
59+
const username = this.generateUsername(connection, flags['base-username']);
6660
this.log(`Generated username: ${username}`);
6761

6862
// Always check for available agent user licenses
@@ -115,24 +109,8 @@ export default class OrgCreateAgentUser extends SfCommand<AgentUserCreateRespons
115109
};
116110
}
117111

118-
private async generateUsername(
119-
connection: Connection,
120-
username: string | undefined,
121-
baseUsername: string | undefined
122-
): Promise<string> {
123-
// If explicit username provided, validate it's unique
124-
if (username) {
125-
const existingUser = await this.checkUsernameExists(connection, username);
126-
if (existingUser) {
127-
throw new SfError(
128-
`Username "${username}" already exists in the Salesforce universe. Usernames must be globally unique.`,
129-
'UsernameExistsError',
130-
['Choose a different username', 'Omit --username to auto-generate a unique username']
131-
);
132-
}
133-
return username;
134-
}
135-
112+
// eslint-disable-next-line class-methods-use-this
113+
private generateUsername(connection: Connection, baseUsername: string | undefined): string {
136114
// Generate username with GUID
137115
const guid = randomUUID().replace(/-/g, '').substring(0, 12);
138116

@@ -154,24 +132,13 @@ export default class OrgCreateAgentUser extends SfCommand<AgentUserCreateRespons
154132
const orgUsername = orgIdentity.username;
155133
if (!orgUsername) {
156134
throw new SfError('Unable to determine org username for generating agent user username', 'OrgUsernameError', [
157-
'Specify an explicit --username or --base-username',
135+
'Specify a --base-username',
158136
]);
159137
}
160138
const domain = orgUsername.split('@')[1];
161139
return `agent.user.${guid}@${domain}`;
162140
}
163141

164-
private async checkUsernameExists(connection: Connection, username: string): Promise<boolean> {
165-
try {
166-
const result = await connection.query<{ Id: string }>(`SELECT Id FROM User WHERE Username = '${username}'`);
167-
return result.totalSize > 0;
168-
} catch (error) {
169-
// If query fails, assume username might exist to be safe
170-
this.warn(`Unable to verify username uniqueness: ${error instanceof Error ? error.message : String(error)}`);
171-
return false;
172-
}
173-
}
174-
175142
private async checkAgentUserLicenses(connection: Connection): Promise<void> {
176143
// Query the Einstein Agent User profile to get its associated license
177144
const profileResult = await connection.query<{

test/unit/org/create/agent-user.test.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,11 @@ describe('org:create:agent-user', () => {
2424
expect(OrgCreateAgentUser.summary).to.exist;
2525
expect(OrgCreateAgentUser.flags).to.exist;
2626
expect(OrgCreateAgentUser.flags['target-org']).to.exist;
27-
expect(OrgCreateAgentUser.flags.username).to.exist;
2827
expect(OrgCreateAgentUser.flags['base-username']).to.exist;
2928
expect(OrgCreateAgentUser.flags['first-name']).to.exist;
3029
expect(OrgCreateAgentUser.flags['last-name']).to.exist;
3130
});
3231

33-
it('should export AgentUserCreateResponse type', () => {
34-
// Type is exported from the module
35-
const response: import('../../../../src/commands/org/create/agent-user.js').AgentUserCreateResponse = {
36-
userId: '005xx000000000001',
37-
username: 'test@example.com',
38-
profileId: '00exx0000000001',
39-
permissionSetsAssigned: [],
40-
permissionSetErrors: [],
41-
};
42-
expect(response).to.exist;
43-
});
44-
4532
it('should throw InvalidBaseUsernameError for invalid base username format', () => {
4633
// This test validates the error without needing a real org
4734
const error = new SfError(

0 commit comments

Comments
 (0)