[SalesForce] SOAP Stub Call out XML Request Data in Apex not in debug log

I like to capture and store XML Request data in custom object before making SOAP api call out for some special purpose, I don't currently see option to get the actual request data in apex, the alternative is manually writing apex code to create soap envelope and store it before making call out, its lot of work i feel. Any suggestions?

Thanks

Best Answer

Your options are to extract the CALLOUT_REQUEST from the debug log (Callout category at the Info level) or to make the SOAP request via Apex. The former will be problematic as it needs to occur after the transaction completes. That's fine for debugging, but not so easy for production. Also, the CALLOUT_REQUEST logging isn't generated in every environment.

I've made an alternative version of Wsdl2Apex that generates the required Apex from the WSDL. You can get it for free in the FuseIT SFDC Explorer (Disclosure: This is my current employer).

After selecting the WSDL, change the Select Method Type to "SOAP and HTTP". SOAP and HTTP generation

The resulting Apex class that gets generated will have an addition method with the _Http suffix that uses an HttpRequest and generates the XML required. You could log that XML as required.

SOAP request via HttpRequest

There is also the open source version of Wsdl2Apex. That would take a bit of work, but you could modify the generated Apex to log the request. It would probably be easier to log the request objects that are passed to WebServiceCallout.invoke rather than the XML that results.