+ Start a Discussion
Vin BVin B 

Hi, when I render word doc from a vf page,Instead of getting downloaded I want the word document to be saved in salesforce documents.Is there any way to achieve it?

Amit Singh 1Amit Singh 1

You can create a custom button on Detail page of that record and from that button call javascript which will be responsible for calling the method of apex class. In apex calss you can write the logic to save the word into document.

Let me know if this helps :)

Hi VinB,

Were are you getting your word document from..? What is the source of the document (for eg: Attachment or RESP API response..etc), as long as you have first retrived the document with in apex memory then you can definately get it copied over to documents. The code given below could possible help.
Document document; document = new Document(); 

/*All you need is the body of the word document, if the source of the document is an attachment then the attachment body is already a BLOB, in other cases you might need to cast it into a BLOB*/

document.Body = Blob.valueOf('Some Text'); 
document.DeveloperName = 'my_document'; 
document.IsPublic = true; 
document.Name = 'My Document'; 
document.FolderId = [select id from folder where name = 'My Docs'].id; 
​insert document;

Vin BVin B

yeah ..It worked... thank you very much guys :) ..By the way any idea how can make that word doc read only while rendering from vf page itself?