2

I need guidance with our current SAP - Salesforce situation. We already have implemented a few outbound HTTP request classes. However, in those classes, it was Salesforce which determined when to run the class and so, when to do the callout.

Our current SAP - Salesforce situation is a bit different. Every change in SAP sends a SOAP message from SAP. This has to be caught in an Apex Class. So, I need some kind of listener that can catch the SOAP messages.

Do you have ay information to point me in the correct direction? Or even an example I can use to understand the best solution?


EDIT (from comments):

The Apex class has to be a listener. At the moment, we cannot change the SAP interface (no resources). Also, in the interface it is nowhere defined to point to Salesforce, so the apex class has to be a listener to the SAP web service, and as soon as the web service sends out SOAP messages, it needs to capture an treat it.

0

Basically, there are two ways to expose an API so you receive an inbound message.

One is creating a REST controller:

@RestResource(urlMapping='/SapHandler/*')
global with sharing class SapHandlerWS{

  @HttpPost
    global static String doSomething() {
        // Business logic
    }
}

The other one is a SOAP-based web service:

global class SapHandlerWS{ 
  webservice static Id doSomething(){ 
    // Business logic
  } 
}

Nonetheless, as far as I'm concerned, there is no way to enable Salesforce to listen to a service waiting for events specific to that service.

You can find the Streaming API which allows you to emit events and there is also the Platform Events which allow you to emit via Apex/Flows events so that 3rd party apps can subscribe to them, and they also allow 3rd party apps to emit them so you can create a custom service in Apex that listens to them. Check this article for a detailed example.

This is how you would code an Apex trigger for a Platform event (example from before article):

trigger onMixApproved on Mix_Approved__e (after insert) {
    List mixes = new List();

    for (Mix_Approved__e event : Trigger.New) {
        Merchandising_Mix__c mix = new Merchandising_Mix__c();
        mix.Id = event.Mix_Id__c;
        mix.Status__c = 'Approved by Manufacturing';
        mix.Confirmation_Number__c = event.Confirmation_Number__c;
        mixes.add(mix);
    }

    update mixes;  
}

Regardless, from what you said, you can't modify your SAP code so you wouldn't be able to publish Force.com platform events, nor call the Apex Web Services... I'm not sure what you're trying to do is actually possible.

In this article you will find many examples of how to integrate with the Force.com platform via Web Services, in case you're interested.

  • Thanks for the info, I will get back to you soon probably :) – bartvd Feb 7 '18 at 6:49
  • @bartvd I would recomend you mark this as answered (if it has), and open a new question next time, with more specifics. – Javier García Manzano Feb 7 '18 at 7:48
  • I already have a question it seems. The Apex class has to be a listener. For the moment, we cannot change the SAP interface (no resources). and in the interface it is nowhere defined to point to Salesforce. So the apex class has to be a listener to the SAP web service, and as soon as the web service sends out SOAP messages, it needs to capture an treath it. – bartvd Feb 7 '18 at 7:51
  • @bartvd StackExchange doesn't work like that. You have to try and make questions as detailed as possible so someone can answer them in a single "answer". Comments are to clarify aspects of the question, not for answering more questions. In any case, I'll try and edit my answer to hopefully answer you better. – Javier García Manzano Feb 7 '18 at 8:32
  • @bartvd there you go! – Javier García Manzano Feb 7 '18 at 9:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.