[SalesForce] matching a WebService class to an inbound request whose format I cannot change

Say I have a SOAP message heading for my org, kind of like a flaming meteorite:

  • I don't really know where it came from,
  • I won't be able to touch it before it arrives,
  • I can't change where it lands, just what it lands on,

All I know is that I need to handle it with a WebService method and it kinda looks like this:

<Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <Body>
    <notifications>
      <ObjId>000000000000000AAA</ObjId>
      <Notification>
        <Id>04ld000000OEiP5AAL</Id>
        <sObject xsi:type="sf:Custom__c">
          <sf:Id>a00d000000QEPOjAAP</sf:Id>
        </sObject>
      </Notification>
    </notifications>
  </Body>
</Envelope>

So I eyeball the transmission above and start to write a WebService class that might fit:

global class NotificationService {

  global class Notification {
    webService String Id;
    //webService String sObject;
  }

  static webService Boolean notifications(String ObjId, List<Notification> Notification) {
    return true;
  }

}

Then I make sure the SOAP message is destined for the above web service endpoint and let the class handle one message.

I receive this error:

No operation available for request {}notifications, please check the WSDL for the service.

It appears Salesforce Web Services won't touch an inbound request without this correct. So let's pretend I can change the namespace (which I can't) and the inbound message now reads <notifications xmlns="http://soap.sforce.com/schemas/class/NotificationService"> – now the handler will start running OK, and of course encounter issue with the format.

Next I'll receive this error:

There is no public member called 'sObject' in the Apex class 'Notification'

But, alas, sObject is a reserved word. I will struggle to save a public member with that name. Any thoughts or guidance are very welcome:

1) Can I get the web service handler to ignore the namespace of the inbound message?

2) Can the handler's signature to match the inbound request, including reserved words?

Best Answer

While I'd be happy (and surprised!) to see an implementation using the webservice framework, I think it's impossible. The documentation keeps silence about adjusting namespaces or field names, and both are handled internally.

There is some hope though. Salesforce outbound messages are simple enough to successfully accept them with Apex REST. You could expose a method with no parameters as @HttpPost, grab the message from RestContext.request.requestBody and then parse it into DOM.

Related Topic