question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Give an option for sfdx force:user:create to make usernames unique (like for sandbox)

See original GitHub issue

Is your feature request related to a problem? Please describe. The sfdx force:user:create command is great to create users on a Scratch Org. However, as usernames need to be unique across all orgs, we can’t set a specific username in the user file. It would be cool to have a way to create the user anyway, appending an org related string at the end to make it unique, like what’s done for sandbox.

What are you trying to do I have a repo with a user that needs to be created. A file that looks like this:

{
    "Username": "richard@piedpiper.com",
    "FirstName": "Richard",
    "LastName": "Hendricks",
    "profileName": "Standard Platform User"
}

If 2 developers try to create a Scratch Org and create this user, only one of them will succeed, because of username uniqueness.

Describe the solution you’d like I’d like a new flag on the sfdx force:user:create command to force username to be unique. It looks like Scratch Orgs don’t have a “name” like a sandbox has, so this could be adding the org id to the username. So running the command with the new flag would end up creating the user in the Scratch Org (let’s say Org Id 00DS0000003acEuMAI) with the username richard@piedpiper.com.00ds0000003aceumai. We would use 18 character case safe Id as username is lowercase. The flag name could be something like --appendorgid or --forceuniqueness.

Describe alternatives you’ve considered I thought about wrapping the existing command in one of mine, something like sfdx texei:user:create, but I think this would make sense to bring it to the official command.

Additional context The idea behind this feature request is to be able to push metadata that contains usernames to a Scratch Orgs. Some are replaced on the fly with the scratch org user by the sfdx force commands, but not all of them. For instance Worfklow Field Update on Account Owner, or Approval Process on Account have to select a username at some point. It can’t be replaced by a queue or a public group. Thus today it just can’t be pushed to the Scratch Org. With this, I could create the related users needed in the metadata, and just using the org id on the username while doing push/pull via a sfdx hook.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
mshanemccommented, Mar 22, 2021

shipped!

2reactions
FabienTailloncommented, Jan 29, 2021

@ImJohnMDaniel yes, that’s not exactly what I want, I think I’ve been unclear.

Let’s say I have a workflow field update that under some conditions will change the Account owner to “Richard Hendricks”. If I want to push that metadata in the Scratch Org I can’t because there is a username in the metadata, and this username doesn’t exist in the Scratch Org. Plus this one has to be a username, it can’t be replaced by a queue or a public group like it can be done for some other metadatas.

I could still replace on the fly the username in the metadata with the scratch org username, but then what happens if I have a user story that is something like “replace account owner in this workflow from Richard Hendricks to Erlich Bachman”.

I wouldn’t be able to do it in the Scratch Org. So what’s the point of having it in the repo/scratch org if I can’t really update it ? Also, what if I change anything else in the workflow, and pull ? The metadata would then contain the scratch org user ?

Or worse, what if I have 5 different workflows or any metadata, that references 5 differents usernames. I can replace them on the fly, but then on the scratch org the metadata would reference the same username instead of 5 different ones. So even if on pull I replace on the fly the usernames the other way round, how do I know which username should be replaced and where ?

So what I would like to do is to create 2 usernames in the scratch org, richard@piedpiper.com and erlich@piedpiper.com, and see them created as richard@piedpiper.com.00ds0000003aceumai and erlich@piedpiper.com.00ds0000003aceumai.

Then I would be able to push the metadata as is, the same way as pushing this workflow in a sandbox will link it automatically to richard@piedpiper.com.mysandboxname. I’m working on a plugin using CLI hooks to achieve this, but that won’t work until I can create a user with a specific username, not a random one.

What do you think ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

user Commands | Salesforce CLI Command Reference
sfdx force:user:create -a testuser1 -f config/project-user-def.json ... Set an alias for the created username to reference within the CLI.
Read more >
SalesforceDX: Log in to sandbox by username/password from ...
Another route is to login to the sandbox by hand once, locally, via force:auth:web:login . Then do sfdx force:org:display -u <username> -- ...
Read more >
Salesforce CLI Release Notes (sfdx Commands) - GitHub
You have a few options: If you want to use the new commands with an existing scratch org or sandbox, run force:source:legacy:tracking:clear ...
Read more >
SEE ALSO User sObject API Reference Create a Scratch Org ...
Specify the scratch org or Developer Hub username or alias at thecommand line if ... This example adds the City option.sfdx force:user:create --setalias ......
Read more >
Salesforce DX Developer Guide - manualzz
You have different options to create a Salesforce DX project depending on how you ... Usernames are unique within the entire Salesforce ecosystem...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found