public class FileCopyHandler { // public static void syncToFileCopy(List newList) { // System.debug('==> FileCopyHandler.syncToFileCopy called. Total records: ' + newList.size()); // // Set contentDocIds = new Set(); // // for(ContentVersion cv : newList){ // // if(cv.ContentDocumentId != null){ // // contentDocIds.add(cv.ContentDocumentId); // // } // // } // // System.debug('ContentDocumentIds collected: ' + contentDocIds); // // // Fetch existing File Copy records (if any) by File Id // // Map existingFileCopyMap = new Map(); // // for(File_Event__c fc : [SELECT Id, File_Id__c FROM File_Event__c WHERE File_Id__c IN :contentDocIds]){ // // existingFileCopyMap.put(fc.File_Id__c, fc); // // } // // System.debug('Existing File_Event__c records fetched: ' + existingFileCopyMap.keySet()); // // List recordsToInsert = new List(); // // for(ContentVersion cv : newList){ // // if(cv.ContentDocumentId == null) continue; // // if(existingFileCopyMap.containsKey(cv.ContentDocumentId)){ // // System.debug('Skipping existing File_Event__c for FileId: ' + cv.ContentDocumentId); // // continue; // // } // // File_Event__c fc = new File_Event__c(); // // fc.File_Id__c = cv.ContentDocumentId; // // fc.HIC_FilesME__Event_Type__c = 'Salesforce Content Version Created'; // // // Map fields // // fc.HIC_FilesME__Title__c = cv.Title; // // fc.HIC_FilesME__Description__c = cv.Description; // // fc.HIC_FilesME__File_Extension__c = cv.FileExtension; // // fc.HIC_FilesME__File_Type__c = cv.FileType; // // fc.HIC_FilesME__File_Location__c = 'ContentVersion'; // // fc.HIC_FilesME__File_URL__c = '/sfc/servlet.shepherd/document/download/' + cv.ContentDocumentId; // // fc.HIC_FilesME__Size__c = cv.ContentSize; // // fc.HIC_FilesME__Record_Id__c = cv.FirstPublishLocationId; // // fc.OwnerId = cv.OwnerId; // // recordsToInsert.add(fc); // // System.debug('Adding new File_Event__c for FileId: ' + cv.ContentDocumentId); // // } // // if(!recordsToInsert.isEmpty()){ // // insert recordsToInsert; // // System.debug('Insert completed successfully. Total new records: ' + recordsToInsert.size()); // // } else { // // System.debug('No new File_Event__c records to insert.'); // // } // List recordsToInsert = new List(); // for(ContentVersion cv : newList){ // File_Event__c fc = new File_Event__c(); // fc.File_Id__c = cv.ContentDocumentId; // fc.HIC_FilesME__Event_Type__c = 'Salesforce Content Version Created'; // // Map fields // fc.HIC_FilesME__Title__c = cv.Title; // fc.HIC_FilesME__Description__c = cv.Description; // fc.HIC_FilesME__File_Extension__c = cv.FileExtension; // fc.HIC_FilesME__File_Type__c = cv.FileType; // fc.HIC_FilesME__File_Location__c = 'ContentVersion'; // fc.HIC_FilesME__File_URL__c = '/sfc/servlet.shepherd/document/download/' + cv.ContentDocumentId; // fc.HIC_FilesME__Size__c = cv.ContentSize; // fc.HIC_FilesME__Record_Id__c = cv.FirstPublishLocationId; // recordsToInsert.add(fc); // } // if(!recordsToInsert.isEmpty()){ // insert recordsToInsert; // System.debug('Inserted File_Event__c records: ' + recordsToInsert.size()); // } else { // System.debug('No records to insert.'); // } // } }