Q:

Deleting a record

Recently I asked a question and this is a follow up to that one
So I got it all worked out, but now my question is how to do I delete the record that I added? When users create this form it goes for approval, and during that approval someone may have to change the Rep, because they may make a mistake or simply don't know who it is on creation, so if someone changes the Rep I want to delete their sharing privileges that I initially gave them.  Now I'm being told it can't be done, and they deal with it already in other instances(manual process).  But I think it can be done.  The following is my code, at the top it is properly adding the user, but I also now check to see if the oldMap != the new one.  I've been looking into DeleteResult[] and delete, but I don't see many examples and I'm pretty confused on how to move forward.
try{
    if(Rep3SetMap.containsKey(s.Rep_3__c)){                            
        splitSharesToInsert.add(new Split__Share(ParentId = s.id , 
            UserOrGroupId = Rep3SetMap.get(s.Rep_3__c).Commission_Correction_User__c, 
            AccessLevel = 'Read'));

        if(!splitSharesToInsert.isEmpty()){           
            Database.Saveresult[] rsr3 = Database.insert(splitSharesToInsert, false);                             
        }
    }
    if(Trigger.oldMap.get(s.Id).Rep_3__c != s.Rep_3__c){ 
        // delete rsr3;          
        // Database.DeleteResult[] drsr = Database.delete(splitSharesToInsert,false);
    }                                                    
}catch (NullPointerException e){ 
    System.debug('NullPointerException' + e);   
} 

A:

Simply run a query for the permission query and then run a delete on it:
delete [SELECT Id FROM Split__Share WHERE ParentId = :pId AND UserOrGrouppId IN :myGroup];

2 things to note
1) You should delete the shares BEFORE adding the new ones so that you don't essentially have 2 copies of the same thing.  This will cause an error in the database.
2) You likely need to turn the above query into a dynamic query because you need to build the ParentIds and UserOrGroupIds in pairs rather than a whole set together.  If this is something you need help on, then a second related question would be likely a good idea so that if you run into issues you aren't confusing things.

