+ Start a Discussion
Jamz_2010Jamz_2010 

Reading a file or Document

Hi all

 

Is there anyway of reading a file (using a file upload) or document present in salesforce within apex code? Anything on this would help as there doesn't appear to be any documentation around.

 

Thanks for any help

 

James

davidpadburydavidpadbury

Hi James,

 

I'm afraid I don't know much about the file uploads, but to read a document from Salesforce you can use something like this -

 

Document doc = [select id from Document where id = 'XXXXXXXXXXXXXXX' limit 1];
String docContent = doc.body.toString();

 

If you want to change the content of the document you can use,

 

doc.body = Blob.valueOf('New Content')
update doc;

 

I hope this helps!

 

David.