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
Kenn K.Kenn K. 

How do I create a webservice that sends record information as xml?

I want to regularly send all account information from salesforce to another external system that will accept it as xml. I have the end point url for the external system and the fields that needs to be sent. 

How do I go about creating this? I assume I will have to schedule this to run daily at a particular time.

Please help.



Rise AnalyticsRise Analytics



You can send outbound messages using Apex and using the Apex Scheduler to set it up to run daily.


Kenn K.Kenn K.

Thanks for your response but I don't think an outbound message will work in my scenario. What I want to do is query all the accounts and send it out to the external system as an xml file. I won't be able to query all the accounts with a workflow.

Kalpana ReddyKalpana Reddy
you need to write an apex class which reads account records and send the information to web service. you will have to first load the external system web service wsdl into salesforce then use above class to send the info to it. All the information in soap web services will be XML by default.
Kenn K.Kenn K.

Thanks Kalpana. Do you have a sample code I could look at. It'll be a good starting point and really helpful.

Also, since I am dealing with a lot of records on a nightly basis, I was thinking something inline with batch apex.


public String getXml() {

List<Account> accList = [select id, Name from account];
XmlStreamWriter w = new XmlStreamWriter();
w.writeStartDocument(null, '1.0');

for(Account acc :  [select id, Name from account]){
w.writeStartElement('Id', acc.Id);

w.writeStartElement('Name', acc.Name);


String xmlOutput = w.getXmlString();
return xmlOutput;



This might help you to create your xml.