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.
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;