How to generate a file and store it under Document using Apex in Salesforce?

How to generate a file and store it under Document using Apex in Salesforce?

Sample Code:          

            Document d = new Document();       
            d.FolderId = ’00l90000001KHtg’;    //Id of the folder under Documents
            d.Name = e.Name + Date.Today();       
            d.ContentType = ‘text/plain’;       
            d.Body = Blob.valueOf(e.Name + ‘ ‘ + e.State__c);               
            
             insert d;


Cheers!!!

Leave a Reply