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

How to Return a Constructed SOAP Body instead of Salesforce generated SOAP Body from a Webservice



I wish to have webservice functions which when called I will create a SOAP body which I then return in my response.  If I set the return type to String for my webservice function the stting gets included as CData in a <result> element.




<soapenv:Envelope xmlns:soapenv="" xmlns="">
<result><![CDATA[<soapenv:Body><GetMsgRS><result>Success: Name=My Test</result></GetMsgRS></soapenv:Body>]]></result>


If I wish to override the SOAP Body generated by Salesforce and instead make it my own generated SOAP body what is the return type I need to use for my function?


Thanks in advance for any help.




Hi @SalesRed,


I also have to return an XML in the response.


According to the Apex Web Services and Callouts documentation, salesforce supports the token datatype of WSDL, which seems to be the most compatible datatype for CDATA.


Unfortunately, I didn't find find any apex datatype to be returned as token.


The most compatible datatype I found was Blob, it results as xsd:base64Binary, which can be decoded by the consumer.