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
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
Hello, 

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 :)

Thanks!
 
magicforce9magicforce9
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.contentType="application/msWord";
document.DeveloperName = 'my_document'; 
document.IsPublic = true; 
document.Name = 'My Document'; 
document.FolderId = [select id from folder where name = 'My Docs'].id; 
​insert document;
Cheers,
Mohammed

 
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?