global with sharing class UpdateContentDocumentBatch implements Database.Batchable, Database.Stateful{ public List parentIdList; public UpdateContentDocumentBatch() { } public UpdateContentDocumentBatch(List parentIdList) { this.parentIdList = parentIdList; } global Database.QueryLocator start(Database.BatchableContext bc) { String querysql = 'select Id, FileName__c, InfoId__c, InfoType__c, subInfoType__c, UpdateDate__c, ParentRecordId__c, LastModifiedBy.Name from FileAddress__c where UpdateDate__c != null and LastModifiedDate < TODAY and ParentRecordId__c like \'a4L%\' '; if (parentIdList != null && parentIdList.size() > 0) { querysql += 'and ParentRecordId__c in :parentIdList'; } System.debug('sql======>' + querysql); return Database.getQueryLocator(querysql); } global void execute(Database.BatchableContext BC, List fileList) { try { List idList = new List(); for (FileAddress__c fileAddress : fileList) { idList.add(fileAddress.ParentRecordId__c); } Map tenderList = new Map([SELECT Id, Original_ID__c FROM Tender_information__c WHERE Original_ID__c IN :idList]); Set temderIdLIst = tenderList.keySet(); List contentVersionList = [SELECT Id, FirstPublishLocationId, Title, Description FROM ContentVersion where FirstPublishLocationId IN :temderIdLIst]; Map> tenderMap = new Map>(); for (Tender_information__c tender : tenderList.values()) { Map mso = new Map(); for (FileAddress__c fileAddress : fileList) { if (fileAddress.ParentRecordId__c == tender.Original_ID__c) { String descrip = fileAddress.InfoId__c + ';' + fileAddress.InfoType__c + ';' + fileAddress.subInfoType__c + ';' + fileAddress.UpdateDate__c; mso.put(fileAddress.FileName__c, descrip); } } tenderMap.put(tender.Id, mso); } for (ContentVersion content : contentVersionList) { if (tenderMap.containsKey(content.FirstPublishLocationId)) { Map contentMap = tenderMap.get(content.FirstPublishLocationId); if (contentMap.containsKey(content.Title)) { System.debug('description=======>' + contentMap.get(content.Title) + ';---' + content.FirstPublishLocationId); content.Description = String.valueOf(contentMap.get(content.Title)); } } } // Database.update(contentVersionList, false); update contentVersionList; update fileList; } catch (Exception e) { System.debug('error========?' + e.getLineNumber()); System.debug('error========>' + e.getMessage()); } } global void finish(Database.BatchableContext BC) {} public static void test1(){ Integer i = 0; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; } }