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
SF Beginner 2019SF Beginner 2019 

Check if the value is same just update else delete

I have this code, wherein it deletes the record when there is a value, how can I achieve to update if the values like UserIdforCsr is just the same?
public static void NewSharing(Set<Id> oldRecords){
        try{       
            CSRShareList = New List<SObject> ();
            ObjectName=new List<Id>(oldRecords).get(0).getSObjectType().getDescribe().getName();
            String strqy ='select id,UserIdforCSR,parentid,RowCause  from';
            
            if(ObjectName == assMember){
                strqy = strqy + ' Assistant_Sharing ';
            }
            if(ObjectName == secMember){
                strqy = strqy + ' Secretary_Sharing ';
            }
            if(ObjectName == 'Account'){
                strqy = 'select id,UserIdforCSR,AccountId,RowCause  from' + ' AccountShare where AccountId in:oldRecords';
            }
            if(ObjectName == secMember || ObjectName == assMember){
                strqy = strqy+'where ParentId in:oldRecords ';
            }
            CSRShareList.addAll(Database.query(strqy));

            if(CSRShareList !=null && CSRShareList.size()>0){
                delete CSRShareList;
            }
        }