I was under the impression that the
Username field on the
User object is globally unique. In other words, even if a value is used in some other instance, that means I cannot create a
User record with that same value. Whether sandbox or production, an instance is an instance.
The documentation seems to back up this belief (emphasis mine):
Create, Filter, Group, idLookup, Sort, Update
Required. Contains the name that a user enters to log into the API or the user interface. The value for this field must be in the form of an email address. It must also be unique across all organizations. If you try to create or update a User with a duplicate value for this field, the operation is rejected.
Each inserted User also counts as a license. Every organization has a maximum number of licenses. If you attempt to exceed the maximum number of licenses by inserting User records, the create is rejected.
However, today I wanted to quickly create a
User in our full sandbox, so I exported the record I wanted from our production instance, then inserted it in the sandbox, all using Data Loader. I only realized after I clicked Finish to fire off the job, that I had forgotten to change the
Username. I was sure I had set myself back when, to my surprise, the insert succeeded. The two records had the same
Username, and the operation was allowed.
Was my understanding incorrect? Is it only unique in tandem with the
Organization.IsProduction value? Is this behavior a bug?
Since Eric deleted his answer, Salesforce itself claims the behavior is as I expected (emphasis mine):
All Salesforce usernames are unique, for all users, across all Organizations (including Trial Orgs, Production orgs and Sandboxes).