global with sharing class UpdateFileAddressBatch implements Database.Batchable, Database.Stateful{ public List parentIdList; public UpdateFileAddressBatch() { } public UpdateFileAddressBatch(List parentIdList) { this.parentIdList = parentIdList; } global Database.QueryLocator start(Database.BatchableContext bc) { String querysql = 'select Id, FileName__c, ViewLink__c, DownloadLink__c from FileAddress__c where LastModifiedDate < TODAY and ParentRecordId__c = \'FrameNumManage\' '; if (parentIdList != null && parentIdList.size() > 0) { querysql += 'and Id in :parentIdList'; } querysql += ' Limit 200'; 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.FileName__c); } List contentVersionList = [SELECT Id, FirstPublishLocationId, Title, Description FROM ContentVersion where Title IN :idList AND Description = 'FrameNumManage']; System.debug('idList===' + JSON.serialize(idList)); for (FileAddress__c fileAddress : fileList) { for (ContentVersion content : contentVersionList) { if (fileAddress.FileName__c == content.Title) { fileAddress.ViewLink__c = '/sfc/servlet.shepherd/version/renditionDownload?rendition=SVGZ&versionId=' + content.Id + '&operationContext=CHATTER'; fileAddress.DownloadLink__c = '/sfc/servlet.shepherd/version/download/' + content.Id; } } } // Database.update(contentVersionList, false); 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++; } }