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
Neha Arora 50Neha Arora 50 

How to delete partner community account

Hi, I am trying to delete portal account into my test class, so that user related to that account should automatically get remove from the collaborationGroup.
I have tried to set the user IsActive to false, still unable to delete to that account, and giving me an error --

System.DmlException: Delete failed. First exception on row 0 with id 0036C00000SLUidQAH; first error: DELETE_FAILED, Your attempt to delete rtkek could not be completed because it is associated with the following portal users.: yourusername05112020@gmail.com
: []


This is how I am trying to delete account and to disable user..

List<User> userToDelete = new List<User>([SELECT Name, IsActive FROM User WHERE UserName = 'yourusername05112020@gmail.com']); 
            userToDelete[0].IsActive = false;
            update userToDelete;
            
            List<Contact> contactToDelete = new List<Contact>([SELECT LastName FROM Contact WHERE LastName = 'test']); 
            delete contactToDelete;
            
            List<Account> advisorToDelete = new List<Account>([SELECT Name FROM Account WHERE Name = 'Test Advisor 2']); 
            delete advisorToDelete;
ShirishaShirisha (Salesforce Developers) 

Hi Neha,

You can't delete the Parter Account if the associated user is active.So,please disable the user then only you will be able to disable the parter account.

Please find the steps to disable the account on UI in the below document:

https://help.salesforce.com/articleView?id=networks_partner_community_disable_accounts.htm&type=5&sfdcIFrameOrigin=null

As per the error message,please inactive the user and then try to disable the account.
 

Please mark it as best answer if it answers your query.

Thank you!

Regards,

Shirisha Pathuri

Neha Arora 50Neha Arora 50
Hi Shirisha, 
Thank you for your efforts and reply. I have already tried to disable my user into test class, but due to other functionalities it is giving me a web service callout error.