1

We want to have an xml file which would be consumed by external application from a url. We need to generate an xml file and the external application will be pinging a particular url which we would provide them with which has this xml file.

We currently use sites.

I am generating an XML using apex a apex class. I am not sure how i can expose this xml ? Should i create it as a file? or what are my options?

We need the xml as a url so that the external system can consume it directly from the url

Thanks

1

One viable solution is to use visualforce page to deleiver the content as text/xml.

Here is a simple vf to show the use case

<apex:page contentType="text/xml#test.xml" showHeader="false" sidebar="false" cache="false">
 <?xml version="1.0" encoding="UTF-8" ?>
  <note>
   <to>Tove</to>
   <from>Jani</from>
   <heading>Reminder</heading>
   <body>Don't forget me this weekend!</body>
 </note>
</apex:page>

Note to set the version as 19.0 as after 20.0 somehow salesforce has an issue allowing xml tag.

You can attach your controller as needed and use tags like apex repeat as well.

The other alternative approach is an @http annotated GET method that returns required results in an apex wrapper object. The subscriber of the service can indicate using the content-type as "application/xml" to get an xml response.

| improve this answer | |
  • Thanks Mohit.. This works well but i am told they dont need it as a downloadable option but as an xml that they can read from url. Any thoughts? – Prady Nov 12 '19 at 8:09
  • The other option is generate a public rest service and pass the object. If they set that content type to xml the object will be converted to xml – Mohith Shrivastava Nov 12 '19 at 13:36
  • I have updated the ans – Mohith Shrivastava Nov 12 '19 at 13:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.