public class FileEventQueueableHandler implements Queueable, Database.AllowsCallouts { private List contentVersionIds; private static final Integer MAX_FILES = 10; // max files per job private static final Integer MAX_HEAP = 4000000; // ~4 MB heap limit public FileEventQueueableHandler(List ids) { this.contentVersionIds = ids; } public void execute(QueueableContext qc) { if (contentVersionIds.isEmpty()) return; // Query all ContentVersions List allCVs = [ SELECT Id, Title, Description, FileExtension, FileType, ContentSize, ContentDocumentId, FirstPublishLocationId, OwnerId FROM ContentVersion WHERE Id IN :contentVersionIds ORDER BY CreatedDate ASC ]; // Prepare new records List recordsToInsert = new List(); for (ContentVersion cvItem : allCVs) { if (cvItem.ContentDocumentId == null) continue; File_Event__c fc = new File_Event__c(); fc.File_Id__c = cvItem.Id; fc.HIC_FilesME__Event_Type__c = 'Salesforce Content Version Created'; fc.HIC_FilesME__Title__c = cvItem.Title; fc.HIC_FilesME__Description__c = cvItem.Description; fc.HIC_FilesME__File_Extension__c = cvItem.FileExtension; fc.HIC_FilesME__File_Type__c = cvItem.FileType; fc.HIC_FilesME__File_Location__c = 'ContentVersion'; fc.HIC_FilesME__File_URL__c = '/sfc/servlet.shepherd/document/download/' + cvItem.ContentDocumentId; fc.HIC_FilesME__Size__c = cvItem.ContentSize; fc.HIC_FilesME__Record_Id__c = cvItem.FirstPublishLocationId; // fc.OwnerId = cvItem.OwnerId; recordsToInsert.add(fc); } if (!recordsToInsert.isEmpty()) { insert recordsToInsert; System.debug('Inserted File_Event__c batch. Size=' + recordsToInsert.size()); } } }