Skip to main content
1 of 4

Attachment to File Trigger on Attachment. File not having any content after the attachment insert

Here is my attachment loop to convert into Salesforce Files. The document as Files is created along with the title and content type however it has no content or sometimes '1' or 'MQ==' which is not expected. Any help would be appreciated.

                for(Attachment att : attachtoupdate) {
                     ContentVersion cv = new ContentVersion();
                     cv.ContentLocation = 'S';
                     cv.PathOnClient =att.Name;
                     cv.Origin = 'H';
                     cv.OwnerId = att.OwnerId;
                     cv.Title = att.Name;
                    // cv.VersionData = Blob.valueOf(EncodingUtil.base64Encode(att.body));
                     cv.VersionData = att.body;```