Loading
Passer un appel distant de longue durée en utilisant Omnistudio.OmniContinuation

Passer un appel distant de longue durée en utilisant Omnistudio.OmniContinuation

Pour prendre en charge les appels distants de longue durée, Vlocity prend en charge l'utilisation de l'objet Salesforce Continuation.

Remarque
Remarque À compter de la version Winter ‘23, les Flexcards prennent en charge les appels de longue durée à partir d'une Procédure d'intégration qui contient une Action HTTP ou une Action distante.

Pour plus d'informations sur l'objet Continuation SFDC et l'interface appelable, consultez la documentation Salesforce suivante :

Pour passer un appel distant en utilisant l'objet OmniContinuation et en implémentant l'interface Appelable :

  1. Créez une classe Apex qui implémente l'interface appelable.
  2. Implémentez la méthode de rappel dans invokeMethod. Consultez le code private Object invokeMethod dans l'exemple.
  3. Pour la méthode qui renvoie l'objet OmniContinuation, appelez le constructeur Omnistudio.OmniContinuation.
    OmniStudio.OmniContinuation con = new OmniStudio.OmniContinuation(120);
    con.ContinuationMethod = 'customCallback';
  4. Pour la dernière méthode de rappel de la chaîne qui renvoie la réponse à la Flexcard ou à l'Omniscript, utilisez le code suivant pour récupérer l'état de l'objet OmniContinuation et des étiquettes système.
    Object state = inputMap.get('vlcContinuationCallbackState');
    Object labels = inputMap.get('vlcContinuationCallbackLabels');
  5. Utilisez la méthode Omnistudio.OmniContinuation.getResponse pour récupérer la réponse.

    Exemple de classe OmniContinuationTest.cls

    global with sharing class RemoteActionCallableOmniContinuation implements Callable
    {
        // Dispatch actual methods
       public Object call(String action, Map<String, Object> args) {
           
           Map<String, Object> input = (Map<String, Object>)args.get('input');
           Map<String, Object> output = (Map<String, Object>)args.get('output');
           Map<String, Object> options = (Map<String, Object>)args.get('options');
    
           return invokeMethod(action, input, output, options);
       }
    
        private Object invokeMethod(String methodName, Map<String, Object> inputMap, Map<String, Object> outMap, Map<String, Object> options) 
        {
            Boolean result = true; 
            try
            {
                // the custom methods can have any customized signature, but 
                // PLEASE MAKE USRE YOU ALWAYS PASS IN options 
                if(methodName.equals('populateElements'))
                {
                    // this returns Continuation Object
                    return populateElements(5, inputMap, outMap, options);
                }
                else if(methodName.equals('continuation2')) 
                {
                    return continuation2(8, inputMap, options);
                }            
                else if(methodName.equals('customCallback')) 
                {
                    customCallback(inputMap, outMap, options);
                }
                else 
                {
                    result = false;
                }   
            } 
            catch(System.Exception e)
            {
                result = false;
            }
    
            //outMap.put('nothing', methodName);
            
            return result;
        }
         
        // You can have other parameters as well, but make sure you always pass in Map<String, Object> options
        private Object populateElements(Integer count, Map<String, Object> inputMap, Map<String, Object> outMap, Map<String, Object> options)
        {
            // THIS IS A SAMPLE TO CALL HEROKU NODE SERVICE
            //
            // Make an HTTPRequest as we normally would
            // Remember to configure a Remote Site Setting for the service!
            String url = 'https://node-count.herokuapp.com/'+count;
            HttpRequest req = new HttpRequest();
            req.setMethod('GET');
            req.setEndpoint(url);       
      
            // Create a Continuation for the HTTPRequest       
            OmniStudio.OmniContinuation con = new OmniStudio.OmniContinuation(60);
            con.ContinuationMethod = 'continuation2';
                  
    
            // Create the state
            Map<string, Object> stateAsMap = new Map<String, Object>();
            String label = con.addHttpRequest(req);
            stateAsMap.put('label', label);
    
            // Store the state
            con.state = stateAsMap;
    
            options.put('continuationState', label);
            options.put('continuationCallback', 'continuation2');
            
            // Return it to the system for processing
            return con;       
        }
        
        // callback for the first Continuation
        // this again returns Continuation Object 
        // This is to show you how to serialize multiple long running remote calls
        private Object continuation2(Integer count, Map<String, Object> inputMap, Map<String, Object> options)
        {
            String url = 'https://node-count.herokuapp.com/'+count;
            HttpRequest req = new HttpRequest();
            req.setMethod('GET');
            req.setEndpoint(url);
            
            // Create a OmniContinuationTest for the HTTPRequest           
            OmniStudio.OmniContinuation con = new OmniStudio.OmniContinuation(120);
            con.ContinuationMethod = 'customCallback';
            
            // Create the state
            Map<string, Object> stateAsMap = new Map<String, Object>();
            String label = con.addHttpRequest(req);
            stateAsMap.put('label', label);
            stateAsMap.put('populateElements-label', inputMap.get('vlcContinuationCallbackState'));
       
            // Save the state
            con.state = stateAsMap;
    
            options.put('continuationState', label);
            options.put('continuationCallback', 'customCallback');
            
            // Return it to the system for processing
            return con;
        }
        
        // Last callback method
        // This does NOT return Continuation Object
        // This will return the response back to the FlexCard or OmniScript, therefore need to set outMap
        private Object customCallback(Map<String, Object> inputMap, Map<String, Object> outMap, Map<String, Object> options) 
        {
            // This is how you access the state and labels passed by the Continuation Object
            Object state = inputMap.get('vlcContinuationCallbackState');
            Object labels = inputMap.get('vlcContinuationCallbackLabels');
    
            Map<String, Object> stateAsMap = (Map<String, Object>) state;
        
            // EXAMPLE
            HttpResponse response = OmniStudio.OmniContinuation.getResponse((String)stateAsMap.get('label'));
            Integer statusCode = response.getStatusCode();
    
            if (statusCode >= 2000) 
            {
                // System.log ...
            }
            
            // This goes back to the FlexCard or OmniScript
            outMap.put('responseFromCallableOmniContinuation', 'Response using OmniContinuationWrapperPtc (Using Callable): ' + response.getBody());
        
            return null;
        }
    }
 
Chargement
Salesforce Help | Article