+ 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.

 

Thanks.

Rise AnalyticsRise Analytics

Ken,

 

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

 

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_scheduler.htm

 

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.

AmitdAmitd

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.writeEndElement();
w.writeStartElement('Name', acc.Name);
w.writeEndElement();

}
w.writeEndDocument();


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

 

 

This might help you to create your xml.