1

A simple question, I am attempting to Upsert User records into Salesforce by using 'Username' as the External Id. But I am receiving the following 'DUPLICATE_USERNAME' error:

"Duplicate Username.
The username already exists in this or another Salesforce organization. Usernames must be unique across all Salesforce organizations. To resolve, use a different username (it doesn't need to match the user's email address). DUPLICATE_USERNAME"

I know there is already a user in my org with this exact 'Username', so I would expect the record to be updated, and as it's not creating a new record the duplicate username shouldn't be an issue?... Is my understanding of the Upsert operation incorrect?


Postman Upsert Request:

curl --location --request PATCH 'https://************.my.salesforce.com/services/data/v51.0/sobjects/User/Username/srj@************.co.uk.Invalid' \
--header 'Authorization: Bearer ************' \
--header 'Content-Type: application/json' \
--data-raw '{
  "FirstName": "S",
  "LastName": "RJ",
  "Alias": "srj",
  "Email": "srj@example.com",
  "ContactId": "0031w00000nviAVAAY",
  "ProfileId": "00e1w000000I0GEAA0",
  "CommunityNickname": "srj",
  "EmailEncodingKey": "UTF-8",
  "TimeZoneSidKey": "Europe/London",
  "LocaleSidKey": "en_GB",
  "LanguageLocaleKey": "en_US"
}'

Postman Upsert 400 Response:

[
    {
        "message": "Duplicate Username.<br>The username already exists in this or another Salesforce organization. Usernames must be unique across all Salesforce organizations. To resolve, use a different username (it doesn't need to match the user's email address). ",
        "errorCode": "DUPLICATE_USERNAME",
        "fields": [
            "Username"
        ]
    }
]

Many Thanks

srj737
  • 53
  • 4
  • 1
    Can you show how you are performing the upsert? – David Reed Feb 23 '21 at 18:47
  • @DavidReed, yes, I was using Mulesoft primarily so the configuration is obscured under the hood, but I just replicated the request in Postman to the same DUPLICATE_USERNAME error. I've edited the request and response into the question body. – srj737 Feb 23 '21 at 21:26
  • Did you discover the root cause for this behavior? I am seeing the same error when using a custom field that is unique external id. – Lindsay Rose Jul 20 '22 at 16:52

0 Answers0