+ Start a Discussion
Daniel B ProbertDaniel B Probert 

External xml import

Hi All,

 

I have an external webservice that I am looking to pull data from in salesforce as a batch process. 

 

at the moment if I run the following command I get an xml response

 

curl -X POST -d "username=test@test.com&accesstoken=djkfdjfdkfjdklfjdlk" https://webserver/api/surveys

 

this will give me an output of

 

<Surveys>

<Survey><SurveyID>62</surveyid><SurveyName>Test</SurveyName><owner>test@test.com</owner></survey>

</surveys>

 

Ideally I would want to take this xml file and then populate an object called forms with the surveyid and the surveyname, with the surveyid being the unique reference.

 

any guidance would be appreciated.

 

cheers

dan

 

 

Satish_SFDCSatish_SFDC
Well, you call the external webservice from Apex using Apex Callouts.
Once you get the XML file, you use the XMLStreamReader class to parse the xml. Based the parse data you write apex code to populate the objects.

Link: http://developer.force.com/cookbook/recipe/parsing-xml-using-the-apex-dom-parser

Reference: http://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#StartTopic=Content/apex_System_XmlStreamReader_instance_methods.htm?CSHID=apex_System_XmlStreamReader_instance_methods.htm

Regards,
Satish Kumar
Satish_SFDCSatish_SFDC
And here is some information on Apex Callouts.

http://wiki.developerforce.com/page/Apex_Web_Services_and_Callouts

Regards,
Satish Kumar