Clear/Remove/Clean Pending Service Routing records in Salesforce

Check the below options to Clear/Remove/Clean PSR(Pending Service Routing/PendingServiceRouting) records in Salesforce.

Option 1:
Remove the Routing Configuration from the queue. This will delete all the Pending Service Routing records associated with it.

Option 2:
Change the Ownership of the records that are associated with the Pending Service Routing through WorkItemId field.
Data Loader can be used.
1. Extract the data.
SELECT Id, WorkItemId, GroupId FROM PendingServiceRouting WHERE GroupId = '<Id_Of_The_Queue>'
2. Use update operation with Non-Omni Queue Id/User Id as the Owner Id.
Non-Omni Queue is a Queue without Routing Configuration.


Below Apex can be executed in Anonymous Window.
Sample Apex Code:
List < Case >  listCases = new List < Case >();
List <PendingServiceRouting > listPSRs =
[ SELECT Id, WorkItemId, GroupId FROM PendingServiceRouting WHERE GroupId = '<Id_Of_The_Queue>' ];
for ( PendingServiceRouting objPSR : listPSRs ) {
    //Id to String to use startsWith method
    String strWorkItemId = objPSR.WorkItemId;
    //Checking whether the PSR is for Case record
    if ( strWorkItemId.startsWith( '500' ) ) {
        //Assigning the Case to an User or Non-Omni Queue
        listCases.add( new Case( Id = objPSR.WorkItemId, OwnerId = '<User Id or Non-Omni Queue Id>' ) );

if ( listCases.size() > 0 )
    update listCases;
Please add limit in the SOQL to avoid Governor Limit for DML Operation