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
GunnarGunnar 

Apex and Documents

I have assembled XML with APEX. Want to write the XML to a file in a documents folder.

 

But can't find any reference on how to do this.

 

Any ideas?

 

Thx.

Best Answer chosen by Admin (Salesforce Developers) 
sfdcfoxsfdcfox
Folder f = [SELECT Id FROM Folder WHERE DeveloperName = 'Folder_To_Use'];
// String xmlString;
Document d = new Document(FolderId=f.Id,Body=Blob.valueOf(xmlString),ContentType='text/xml');
insert d;

That's the rough of it.