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
Peter BölkePeter Bölke 

Destructive changes: How to delete Role and Sub-Role

Hello,

during a recent deployment we came across a problem. We tried to delete a role (e.g. named "Role") and a subordinate role (e.g. name "Sub-Role").

Role
|-Sub-Role

first version of our file for destructive changes:
 
<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
    <types>
        <members>Role</members>
<members>Sub_Role</members>
        <name>Role</name>
    </types>
</Package>
this failed with the message
Your attempt to delete the role Role could not be completed because users are currently assigned to that role or at least one role reports to that role.: Role: Sub-Role
then we changed the order of the roles 
<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
    <types>
        <members>Sub_Role</members>
<members>Role</members>
        <name>Role</name>
    </types>
</Package>

This failes with the same message.

Is it possible to define an order of deletion?

Thanks
Peter

 
AnjaneyluAnjaneylu
Hey Peter,

The error is not because of XML format. It's because of destination org having some users with these mentioned roles. so better to remove the roles for those assigned users in destination org. And then deploy again. It works.

Let me know if still any issues !

Thanks 
Anji
Peter BölkePeter Bölke
Hi Anji,

there where no user assigned to the groups. But it is possible to do destructive change pre and post a deployment. i will have look on this.

regards
Peter
AnjaneyluAnjaneylu
Hi Peter,

instead of adding in PreDestructive changes file, add it into post destructive changes file.
It's better to do SOQL query first in the destination org to check if user with role = "Role", If you find any records with this query, then remove the Role on those user records. 

Thanks
Anji
Deepali KulshresthaDeepali Kulshrestha
Hi Peter,
Greetings to you!

- Currently, there is no way to delete a role that is assigned to the user.

->Following are the details that need to be considered when deleting portal roles.
 
    - Roles can be deleted from any point in the hierarchy as long as a user is not assigned. If a user is assigned then, we need to move the users to a different role and then delete the role
    - Remaining roles will be renamed based on the number of roles remaining
        - If 1 role remains, User
        - If 2 roles remain, Manager => User
        - If 3 roles remain, Executive => Manager => User
    - Role Id remains the same and only the name changes
    
->For example, if we have 3 roles for a Partner account and we delete Manager Role, then we will see that there is still a Manager role, because now the Executive role is renamed as Manager.
    - Even though the name is changed to ensure the hierarchy is corrected as shown above, the functionality of the existing role remains the same.
    - Currently, there is no way to delete a role that is assigned to user
    - All actions (adding roles or deleting roles) are logged in the Setup Audit Trial

Reference Link : -
    - https://help.salesforce.com/articleView?id=000329625&type=1

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha.