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
Gopal ChatGopal Chat 

This is my code,and it's mot working can anyone help me

trigger CountNoOfFiles on ContentVersion (after insert,before update,after delete,after undelete) {
    Set<Id> contentDocumentIdSet = new Set<Id>();
    list<Contract> ConToUpdate = new list<Contract>();
    set<id> LinkedEntityId1=new set<id>();
    if(Trigger.isInsert || Trigger.isUpdate|| Trigger.isUndelete){
        for(ContentVersion cv:trigger.new){
            if(cv.ContentDocumentId != null){
                contentDocumentIdSet.add(cv.ContentDocumentId);
            }
        }
    }
    if(Trigger.isDelete){
        for(ContentVersion cv:trigger.old){
            if(cv.ContentDocumentId != null){
                contentDocumentIdSet.add(cv.ContentDocumentId);
            }  
        }
    }
            system.debug('===contentDocumentIdSet'+contentDocumentIdSet);
            List<ContentDocumentLink> cdlForEvent= [SELECT ContentDocumentID, LinkedEntityId FROM ContentDocumentLink 
                                                    WHERE ContentDocumentID IN:contentDocumentIdSet];
            if(cdlForEvent!=null && cdlForEvent.size()>0){
                for(ContentDocumentLink contlink:cdlForEvent){
                    String qtId =  String.valueOf(contlink.LinkedEntityId);
                    qtId = qtId.substring(0,3);
                    if(qtId=='800'){
                        LinkedEntityId1.add(contlink.LinkedEntityId);    
                    }
                }
                system.debug('===LinkedEntityId1'+LinkedEntityId1);
                if(LinkedEntityId1!=null && LinkedEntityId1.size()>0){
                    for(Contract con : [SELECT Id,No_of_Files__c FROM Contract WHERE ID in:LinkedEntityId1]){
                        con.No_of_Files__c+=LinkedEntityId1.size();
                        ConToUpdate.add(con);
                    }
                }
            }
        
    if(ConToUpdate!=NULL && ConToUpdate.size()>0)
     system.debug('===ConToUpdate'+ConToUpdate);
    update ConToUpdate;
}