You need to sign in to do that
Don't have an account?
naresh.sfdc1.3885733215764783E12
Save XML Data File in Attachments
Hi Folks,
i implemented one VF Page for showing Data in XML format.Its showing very perfetly but when i click on Save button on this page,i need to save this Data in Attachments as an XML file.Any ideas....
VF Page:
<apex:page showHeader="false" controller="CLS_xmlGeneration" tabStyle="Reward__c" >
<apex:outputText value="{!xmldata}" style="width:1000px;"/>
</apex:page>
Class :
public class CLS_xmlGeneration {
public String xmldata { get; set; }
public ID recid{get;set;}
public Reward__c rew{get;set;}
Public CLS_xmlGeneration(){
recid=ApexPages.CurrentPage().getParameters().get('Id');
rew =new Reward__c();
rew = [select id,name,Rward_Amount__c,Time_Based_Mgmnt__c,User__c from Reward__c where id=:recid];
Dom.Document doc = new Dom.Document();
XmlStreamWriter w = new XmlStreamWriter();
w.writeStartDocument(null, '1.0');
// w.writeStartElement(null, 'quotas', null);
w.writeStartElement(null, 'Reward', null);
w.writeStartElement(null, 'Id', null);
w.writeCharacters(rew.id);
w.writeEndElement();
w.writeStartElement(null, 'Name', null);
w.writeCharacters(rew.name);
w.writeEndElement();
w.writeStartElement(null, 'UserId', null);
w.writeCharacters(rew.User__c);
w.writeEndElement();
w.writeStartElement(null, 'TimeId', null);
w.writeCharacters(rew.Time_Based_Mgmnt__c);
w.writeEndElement();
w.writeStartElement(null, 'RewardAmount', null);
w.writeCharacters(string.valueof(rew.Rward_Amount__c));
w.writeEndElement();
w.writeEndElement();
// w.writeEndElement();
w.writeEndDocument();
xmldata = w.getXmlString();
w.close();
// doc.LoadXml(xmlOutput);
// system.debug('XML is '+doc.toXmlString());
// xmldata = doc.toXmlString();
}
public pagereference insrtattacmnt(){
PageReference csvPage = Page.VF_XMLinsert_intoAttachment;
csvPage.getParameters().put('Id', recid);
Blob csvBlob = csvPage.getContent();
// dom.Document doc = new dom.Document();
// doc.load(csvPage.getContent().toString());
Attachment attachment = new Attachment();
attachment.Body = csvBlob ;
attachment.Name = 'Rewardfile.xml';
attachment.ParentId = rew.Id;
insert attachment;
return null;
}
}
i implemented one VF Page for showing Data in XML format.Its showing very perfetly but when i click on Save button on this page,i need to save this Data in Attachments as an XML file.Any ideas....
VF Page:
<apex:page showHeader="false" controller="CLS_xmlGeneration" tabStyle="Reward__c" >
<apex:outputText value="{!xmldata}" style="width:1000px;"/>
</apex:page>
Class :
public class CLS_xmlGeneration {
public String xmldata { get; set; }
public ID recid{get;set;}
public Reward__c rew{get;set;}
Public CLS_xmlGeneration(){
recid=ApexPages.CurrentPage().getParameters().get('Id');
rew =new Reward__c();
rew = [select id,name,Rward_Amount__c,Time_Based_Mgmnt__c,User__c from Reward__c where id=:recid];
Dom.Document doc = new Dom.Document();
XmlStreamWriter w = new XmlStreamWriter();
w.writeStartDocument(null, '1.0');
// w.writeStartElement(null, 'quotas', null);
w.writeStartElement(null, 'Reward', null);
w.writeStartElement(null, 'Id', null);
w.writeCharacters(rew.id);
w.writeEndElement();
w.writeStartElement(null, 'Name', null);
w.writeCharacters(rew.name);
w.writeEndElement();
w.writeStartElement(null, 'UserId', null);
w.writeCharacters(rew.User__c);
w.writeEndElement();
w.writeStartElement(null, 'TimeId', null);
w.writeCharacters(rew.Time_Based_Mgmnt__c);
w.writeEndElement();
w.writeStartElement(null, 'RewardAmount', null);
w.writeCharacters(string.valueof(rew.Rward_Amount__c));
w.writeEndElement();
w.writeEndElement();
// w.writeEndElement();
w.writeEndDocument();
xmldata = w.getXmlString();
w.close();
// doc.LoadXml(xmlOutput);
// system.debug('XML is '+doc.toXmlString());
// xmldata = doc.toXmlString();
}
public pagereference insrtattacmnt(){
PageReference csvPage = Page.VF_XMLinsert_intoAttachment;
csvPage.getParameters().put('Id', recid);
Blob csvBlob = csvPage.getContent();
// dom.Document doc = new dom.Document();
// doc.load(csvPage.getContent().toString());
Attachment attachment = new Attachment();
attachment.Body = csvBlob ;
attachment.Name = 'Rewardfile.xml';
attachment.ParentId = rew.Id;
insert attachment;
return null;
}
}
https://developer.salesforce.com/forums/ForumsMain?id=906F00000009Fq0IAE
Regards,
Ashish