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
WilmerWilmer 

How to receive and respond with XML in an Apex webservice?

Hi everybody,

 

I'd like to know how receive a XML string input and respond with a XML string output in an Apex webservice. I already know that this kind of communication is not problem when you use the Generate from WSDL button and call an external webservice. But, how could I receive the required informatio and send the respond by using XML in an apex webservice in order to make other systems talk to SFDC in that language?

 

Is there something like this?

 

 

webservice static XML myApexWebservice(XML MyINPUTString) { XML XML_Response; // here comes more logic; return XML_Response; }

 

 I found the following example:

 

global class AccountPlan { webservice String area; webservice String region; //Define an object in apex that is exposed in apex web service global class Plan { webservice String name; webservice Integer planNumber; webservice Date planningPeriod; webservice Id planId; } webservice static Plan createAccountPlan(Plan vPlan) { //A plan maps to the Account object in salesforce.com. //So need to map the Plan class object to Account standard object Account acct = new Account(); acct.Name = vPlan.name; acct.AccountNumber = String.valueOf(vPlan.planNumber); insert acct; vPlan.planId=acct.Id; return vPlan; } }

 

 Is this the answer am I looking for? But that means if the INPUT/OUTPUT XML is complex, Do I have to simulate all the XML schema by building the required objects?

 

Thank you very much for your help.

 

Regards,

 

Wilmer

 

 

 

 

 

 

 

WilmerWilmer

Well, now I think I was right in the kind of solution:

 

Here is an example:

 

 

global class Update_cls {
// Request
global class WSRequest {
webservice string First_Name;
webservice string Middle_Name;
webservice string Last_Name;
}
// Response
global class WSResponse{
webservice integer Code;
webservice string Description;
}

webservice static WSResponse Procesar_ws(WSRequest Client){

// prepare Response
Update_cls.WSResponse MyResponse = new Update_cls.WSResponse();
// here comes more logic
return WSResponse;
}

}

 

 Now, my question is: how could I set as mandatory one of the values of the WSRequest object?

 

This is part of the XML generated code:

 

<xsd:element name="First_Name" minOccurs="0" type="xsd:string" nillable="true"/>

 As you can see, the field "Fisrt_Name"is not mandatory.

 

I hope this case helps many others.

 

Regards,

 

 

Wilmer

 

 

 

 

Message Edited by Wilmer on 10-19-2009 09:09 PM