buli
2023-07-13 c51e03fbf2f6633d8e88aeec9dcb8df13524df8f
force-app/main/default/classes/Batch_FixAttachmentToFiles.cls
@@ -31,11 +31,11 @@
    Map<string, id> nameParentMaps = new Map<string, id>();
    Set<String> attachmentIds = new Set<String>();
    for (Attachment att : scope) {
      nameParentMaps.put(att.Name, att.ParentId);
      nameParentMaps.put(att.Id, att.ParentId);
      attachmentIds.add(att.Id);
      ContentVersion cVersion = new ContentVersion();
      cVersion.ContentLocation = 'S'; //S-Document is in Salesforce. E-Document is outside of Salesforce. L-Document is on a Social Netork.
      cVersion.PathOnClient = att.Name; //File name with extention
      cVersion.PathOnClient = att.Id; //File name with extention
      cVersion.Origin = 'C'; //C-Content Origin. H-Chatter Origin.
      cVersion.Title = att.Name; //Name of the file
      cVersion.VersionData = att.Body; //File content
@@ -55,7 +55,7 @@
      contentIds.add(cv.id);
    }
    List<ContentVersion> conDocuments = [
      SELECT ContentDocumentId, Title
      SELECT ContentDocumentId, Title, PathOnClient
      FROM ContentVersion
      WHERE Id IN :contentIds
    ];
@@ -63,7 +63,7 @@
    for (ContentVersion cv : conDocuments) {
      ContentDocumentLink cDocLink = new ContentDocumentLink();
      cDocLink.ContentDocumentId = cv.ContentDocumentId; //Add ContentDocumentId
      cDocLink.LinkedEntityId = nameParentMaps.get(cv.Title); //Add attachment parentId
      cDocLink.LinkedEntityId = nameParentMaps.get(cv.PathOnClient); //Add attachment parentId
      cDocLink.ShareType = 'V'; //V - Viewer permission. C - Collaborator permission. I - Inferred permission.
      cDocLink.Visibility = 'AllUsers';
      insertDocLinks.add(cDocLink);