function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Sahba Shabrokh 3Sahba Shabrokh 3 

Trying to delete class but getting an error that says duplicate username in another org

Trying to basicly delete this apex class.

So i have changed the XML file staus to deleted. 

highlted the code and XML and tried to save to server.

But getting errors saying that the username in the test is duplicate. any ideas on how to delete? or overcome this?
 
/*
@Name           : TestUpdateAccountTeamMembers
@Author         : pwittmeyer@gmail.com  
@Date           : 4/3/2015
@Description    : Test Class for UpdateAccountTeamMembers trigger
*/

@isTest(seeAllData=TRUE)
private class TestUpdateAccountTeamMembers {
     static testMethod void validateAccountTeamMembers() {
     
        Profile p = [SELECT Id FROM Profile WHERE Name='Standard User']; 
        User u = new User(Alias = 'standt', 
                            Email='standarduser@testorg.com', 
                            EmailEncodingKey='UTF-8', 
                            LastName='Testing', 
                            LanguageLocaleKey='en_US', 
                            LocaleSidKey='en_US', 
                            ProfileId = p.Id, 
                            TimeZoneSidKey='America/Los_Angeles', 
                            UserName='testUserForTestUpdateAccountTeamMembers@testorg.com');
        insert u;
        User u2 = new User(Alias = 'standt2', 
                            Email='standarduser2@testorg.com', 
                            EmailEncodingKey='UTF-8', 
                            LastName='Testing2', 
                            LanguageLocaleKey='en_US', 
                            LocaleSidKey='en_US', 
                            ProfileId = p.Id, 
                            TimeZoneSidKey='America/Los_Angeles', 
                            UserName='testUserForTestUpdateAccountTeamMembers2@testorg.com');
        insert u2;
         
        /*Account a = new Account(Name = 'Test', Website = 'Http://test.com/', vertical__c = 'Adult',
                                                     Account_Manager_1__c = u.Id);
        insert a;
        
        Account a2 = new Account(Name = 'Test2', Website = 'Http://test.com/', vertical__c = 'Adult');
        insert a2;*/
        Account a = [SELECT Id, Name, Account_Manager_1__c FROM Account LIMIT 1];
        Account a2 = [SELECT Id, Name, Account_Manager_1__c FROM Account where Id != :a.id LIMIT 1];
        
        a.Account_Manager_1__c = u2.Id;
        a.Website_Currency__c = 'GBP';
        update a;
        
        a2.Account_Manager_1__c = u.Id;
        //update a2;
        
        a2.Account_Manager_1__c = null;
        //update a2;  
    }
}

 
Khan AnasKhan Anas (Salesforce Developers) 
Hi Sahba,

Greetings to you!

The user name must be unique across all Salesforce organizations which Salesforce has created till now. A username can only be used once. All Salesforce usernames are unique, for all users, across all Organizations (including Trial Orgs, Production orgs and Sandboxes). 

https://help.salesforce.com/articleView?id=000005244&language=en_US&type=1

In the test class, you can append Datetime.Now() with username String to make it unique.

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas