Skip to main content
Richard Johnson ha fatto una domanda in #Data Management

For example, where I have many email messages, related to cases. Can these emails message become PDF files related to the Case. The goal is to save Data storage space by using File Storage. I've seen scripts to create PDFs, (which can be saved locally) but not scripts to then push that PDF to the File Storage. Flow or Apex solutions sought. Bulk processing appreciated.

2 risposte
  1. 14 ott 2022, 15:29

    Hi!  This code can be used to create a link and relate it to any record you want

    ContentVersion cv = new ContentVersion();

    cv.ContentLocation = 'S';

    // Name of the pdf

    cv.PathOnClient = pdfName + '.pdf';

    cv.Title = pdfTitle;

    // Here you should pass your email body

    cv.VersionData = emailBody;

    insert cv;

    ContentDocumentLink cdl = new ContentDocumentLink();

    cdl.ContentDocumentId = [SELECT Id, ContentDocumentId FROM ContentVersion WHERE Id =: cv.Id].ContentDocumentId;

    cdl.LinkedEntityId = recordId;

    cdl.ShareType = 'V';

    insert cdl;

0/9000