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
davidjbbdavidjbb 

Salesforce and XML

Hello,

 

I need help with the following.

 

I have data within multiple custom objects, however, I need to be able to export the data/ or custom object into an xml file with a button..

 

The xml file should be downloadable.

 

How would I go about to start this and where can I find the information to get the foundation?

 

Regards,

davidjbb

Navatar_DbSupNavatar_DbSup

 Hi,

 

Create a Vf page that will generate the Xml

 

Try  below code snippet as reference:

 

<apex:page controller="TestController" contentType="application/xml"><?xml version="1.0" encoding="UTF-8"?>

    <myNS:stuff>

        <apex:repeat value="{!exportValues}" var="actual">

            <myNS:myTag name="Id" value="{!actual.Id}"/>

            <myNS:myTag namw="Act Name" value="{!actual.Name}"/>       

        </apex:repeat>

    </myNS:stuff>

</apex:page>

 

public with sharing class TestController {

    public TestController() {

        this.values = new ExportValue[] {

            new ExportValue('1', 'Name 1'), new ExportValue('2', 'Name 2')

        };

    }

 

    public ExportValue[] getExportValues() {

        return values;

    }

 

    public class ExportValue {

        public ExportValue(String id, String name) {

            this.id = id;

            this.name = name;

        }

       

        public String id { get; private set; }

        public String name { get; private set; }       

    }

   

    private final ExportValue[] values;

}

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

 

davidjbbdavidjbb

Hi, 

 

Thank you for your quick response. Do you mind explaining to me some of the code/syntax for clarification?
There's an error "Error: Unknown component myns:stuff" (I inserted this to bypass the error until you provide me with further clarification.)

<myNS:stuff xmlns:myNS="http://www.bogussite.com/namespace/myNamespace">


How can you format the XML doc to something like. Of course all the values should be retrieved from fields/objects.

 

<test>
"name", "0", "Contact", "street", "street2", "city", "prov", "postal", "country", "phone", "phone2", "fax", "email@emailaddress.com"
"name2", "0", "Contact", "street", "street2", "city", "prov", "postal", "country", "phone", "phone2", "fax", "email@emailaddress.com"
</test> 

 

I have taken a look at http://boards.developerforce.com/t5/Visualforce-Development/Generating-an-XML-from-VF-page-using-ContentType/m-p/231857#M31168 and it showed what the xml document that is produced. 

 

edit:

 

I adjusted the following code, so i can use the VF page as custom button, which will download the xml doc. I've added the code to download. Please advise. Error: When I tried to test it out. It didn't printout the variable values

 

<?xml version="1.0" encoding="UTF-8"?><myNS:stuff xmlns:myNS="http://www.bogussite.com/namespace/myNamespace">

</myNS:stuff>

 

<apex:page standardController="TestController__c" extensions="TestController" contentType="application/xml#ExportXMLDoc.IMP"><?xml version="1.0" encoding="UTF-8"?>

     <myNS:stuff xmlns:myNS="http://www.bogussite.com/namespace/myNamespace">

        <apex:repeat value="{!exportValues}" var="actual">

            <myNS:myTag name="Id" value="{!actual.Id}"/>

            <myNS:myTag namw="Act Name" value="{!actual.Name}"/>       

        </apex:repeat>

    </myNS:stuff>

</apex:page>
SylverGSylverG

Hi, 

According to me you need to create a controller class where you then create the xml that you want as a string in the controller section

In the VF page you then display the xml string created.

 

on page level you would put

 

<apex:page controller="XmlExportController" contentType="application/xml#test.xml"><?xml version="1.0" encoding="UTF-8"?>
{!xmlString}
</apex:page>

 

the #test.xml will make the browser try to save it as the xml file you are after

 

Will be trying this myself later, however quite sure this works out.

 

Enjoy