5

As stated in the title - I created a scratch org and created additional user on it using SFDX. Then after deleting this environment when I try to create user with the same name on another scratch org I keep getting error:

The username "someusername@example.com" already exists in this or another Salesforce org. Usernames must be unique across all Salesforce orgs.

So, how to delete user (or at least change its name) from a scratch org that I don't have access to anymore?

  • "was not found" to me does not seem to imply you need to delete the user from the other org. It seems to imply you are trying to find a user in your new org that does not exist. Can you provide the code you're using that is throwing the error? – gNerb Feb 5 at 15:45
  • @gNerb my fault, I pasted wrong error message. Take a look now please. – Bartosz Śliwiński Feb 5 at 15:48
  • Are you creating the scratch orgs fairly close together? Running sfdx force:org:delete enqueues an org for deletion but it's not necessarily instant. – David Reed Feb 5 at 15:53
  • @DavidReed That's what I tought too so I gave it around 12 hours span to perform actual deletion. Is there any information from SF how long it may take? – Bartosz Śliwiński Feb 5 at 15:56
8

Scratch Orgs are deleted asynchronously after you run the delete command (or it expires). It will take some time for that username to be freed up, probably at least 24 hours. You'll need to use a different user name in this case, as there's nothing you or Support can do. In the future, rename the user before deleting the org if you wish to reuse the user name in a different scratch org.

7

In addition to @sfdcfox response (which is technically accurate) , I suggest you do not try to reuse the same username in different scratch orgs, this seems a very bad habit and all your project orgs may get quickly messy, even more if you use CI.

You could for example use some suffix for your scratch org usernames, using your project name and the creation date.

Structure : MYNAME@MYPROJECT-scratch-TODAY.com

Example: nico@myproj-scratch-20190502.com

  • Thanks for advice. That's a specific situation I've got here - I plan to use sfdx for teaching purposes and I create users for people who will be logging to SF using those usernames so they shouldn't be random or complicated. – Bartosz Śliwiński Feb 5 at 16:12
  • 3
    tim@testing-may.com, then tim@testing-june.com, are not so complicated :) But if it is for permanent manual tests ... maybe a non-scratch org would be a better option – Nicolas Vuillamy Feb 5 at 16:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.