Loading

Salesforce Platform: Resolve Duplicate Username Error

Publiceringsdatum: Mar 31, 2026
Beskrivning

Scenario: This error occurs when trying to change a User's username to one that already exists in any Salesforce org globally (not just your org

If you are updating user object records using apex class which implements PostCopyScript interface during Sandbox Refresh it may result in below Duplicate Username exception.


Error Message:

EXCEPTION_THROWN|[50]|System.DmlException: Update failed. First exception on row 0 with id 005***************; first error: DUPLICATE_USERNAME, 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). : [Username] 
 

Lösning

Root Cause

This can happen post refresh. Usually the  sandbox copy takes time to go through replication of user records, which is 48 hours.
This is working as designed. As a workaround -

  1. Invoke Apex Scheduler from PostCopyScript implemented class which will delay the update process of user records.

    Reference Guides

        2. If apex class script doesn't work then can raise a Support case to further review this.

NOTE - This process takes maximum 48 hours so after that issue is expected to be resolved.

Knowledge-artikelnummer

000381924

 
Laddar
Salesforce Help | Article