| | |
| | | private Datetime creEndDate = null; |
| | | private String objectApiName = null; |
| | | private Set<String> parentIds = new Set<String>(); //Add by Li Jun 20230703 |
| | | public Batch_FixAttachmentToFiles( |
| | | String objectType, |
| | | Datetime startTime, |
| | | Datetime endTime |
| | | ) { |
| | | public Batch_FixAttachmentToFiles(String objectType, Datetime startTime, Datetime endTime) { |
| | | creStartDate = startTime; |
| | | creEndDate = endTime; |
| | | objectApiName = objectType; |
| | |
| | | return; |
| | | } |
| | | //Insert insertContents; |
| | | List<Database.SaveResult> saveResultsContents = Database.insert( |
| | | insertContents, |
| | | false |
| | | ); |
| | | List<Database.SaveResult> saveResultsContents = Database.insert(insertContents, false); |
| | | insertLog(saveResultsContents, attachmentIds); |
| | | set<Id> contentIds = new Set<Id>(); |
| | | set<Id> contentIds = new set<Id>(); |
| | | for (ContentVersion cv : insertContents) { |
| | | contentIds.add(cv.id); |
| | | } |
| | | List<ContentVersion> conDocuments = [ |
| | | SELECT ContentDocumentId, Title, PathOnClient |
| | | FROM ContentVersion |
| | | WHERE Id IN :contentIds |
| | | ]; |
| | | List<ContentVersion> conDocuments = [SELECT ContentDocumentId, Title,PathOnClient FROM ContentVersion WHERE Id in: contentIds]; |
| | | List<ContentDocumentLink> insertDocLinks = new List<ContentDocumentLink>(); |
| | | for (ContentVersion cv : conDocuments) { |
| | | ContentDocumentLink cDocLink = new ContentDocumentLink(); |
| | |
| | | insertDocLinks.add(cDocLink); |
| | | } |
| | | //Insert insertDocLinks; |
| | | List<Database.SaveResult> saveResultsLinks = Database.insert( |
| | | insertDocLinks, |
| | | false |
| | | ); |
| | | List<Database.SaveResult> saveResultsLinks = Database.insert(insertDocLinks, false); |
| | | insertLog(saveResultsLinks, attachmentIds); |
| | | } |
| | | |
| | | global void insertLog( |
| | | List<Database.SaveResult> saveResults, |
| | | Set<String> attachmentIds |
| | | ) { |
| | | global void insertLog(List<Database.SaveResult> saveResults,Set<String> attachmentIds) { |
| | | Transaction_Log__c traLog = new Transaction_Log__c(); |
| | | List<Map<String, String>> logMapList = new List<Map<String, String>>(); |
| | | for (Database.SaveResult result : saveResults) { |
| | |
| | | logMapList.add(attachmentIdMap); |
| | | traLog.Response__c = JSON.serialize(logMapList); |
| | | traLog.Module__c = 'Attachment COnvert Transaction '; |
| | | insert traLog; |
| | | Insert traLog; |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | global void finish(Database.BatchableContext BC) { |
| | | |
| | | } |
| | | } |