function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Daniele SerraDaniele Serra 

Alternative for attachment in apex. From a string to a file

Hello everybody!
I have this problem: I need to create a file to "attach" into a record. I have this method:

String filename = 'generatedxml_' + Datetime.now();
 Attachment attachment = new Attachment();
attachment.Body = Blob.valueOf('\uFEFF' + content);
attachment.ContentType = 'text/xml';
attachment.Name = filename +'.xml';
attachment.ParentId = parentId;
insert attachment;

But, even it works perfectly for my aim, with the new release '18 it will not work anymore. Some people suggest me to use ContentDocument object but i can't find nothing usable on internet.
So my question: I needto understand how, in apex, create a file from a String, and how attach the file to a record using the new features in lightning experience. Thanks so much.