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
Hemanth.ax1701Hemanth.ax1701 

****URGENT**** Writing XML to a file

Hi,

 

I have a created  a XML String using XMLStreamWriter.

 

 XmlStreamWriter w = new XmlStreamWriter();

 

I am able  display this  String using <apex:OutputText> and that looks fine and well structured. My requirement is to write this XML String to a file and save it in SFDC, so that user can quickly download as XML. Please guide me how do I achieve it. Please treat this as very urgent.

 

 

--

Hemanth

SeAlVaSeAlVa

Something like ...

 

insert new Document(Body=Blob.valueof(w.getXmlString()), contentType='text/xml', type='xml', Name='XXX', FolderID=[SELECT ID FROM Folder WHERE Type='Document' LIMIT 1].id);

 where XXX need to be changed from file to file (otherwise will throw a duplicate exception)

 

Regards

sfdcfoxsfdcfox
That's a very decent answer. Would like to add, you can set FolderId to UserInfo.getUserId() to store the file in the user's "My Documents" folder (to prevent the document from leaking to random people).
Hemanth.ax1701Hemanth.ax1701

Thanks a lot guys. Its working .

 

Would be so helpful, if you suggest me to get the URL for download..more like a file download pop-up.

 

 

--

Hemanth

sfdcfoxsfdcfox
/servlet/servlet.FileDownload?file=<file-id>, just replace <file-id> with the ID value from the document that you inserted. You can set this as an <apex:outputLink>.
Hemanth.ax1701Hemanth.ax1701

This procedure displays the XML file in a separate window in the browser itself but the point is I want to display a pop up asking me to save the file just like a normal download window.

 

Is this possible may be using JavaScript? 

 

Kindly suggest.

 

--

Thanks 

Hemanth