Loading
Realizar una llamada remota de larga duración utilizando OmniStudio.OmniContinuación

Realizar una llamada remota de larga duración utilizando OmniStudio.OmniContinuación

Para admitir llamadas remotas de larga ejecución, Vlocity admite el uso del objeto Continuación de Salesforce.

Nota
Nota A partir de Winter ā€˜23, Flexcards admite llamadas de larga ejecución desde un Procedimiento de integración que tiene una Acción HTTP o una Acción remota.

Para obtener detalles acerca del objeto Continuación de SFDC y la interfaz Llamada, consulte la siguiente documentación de Salesforce:

Para realizar una llamada remota utilizando el objeto OmniContinuación e implementando la interfaz Callable:

  1. Cree una clase Apex que implemente la interfaz Callable.
  2. Implemente el método de devolución de llamada en invokeMethod. Consulte el código de private Object invokeMethod en el ejemplo.
  3. Para el método que devuelve el Objeto OmniContinuación, llame al constructor OmniContinuación.OmniContinuación.
    OmniStudio.OmniContinuation con = new OmniStudio.OmniContinuation(120);
    con.ContinuationMethod = 'customCallback';
  4. Para el último método de devolución de llamada en la cadena que devuelve la respuesta a Flexcard u OmniScript, utilice el siguiente código para obtener el estado del Objeto OmniContinuación y las etiquetas del sistema.
    Object state = inputMap.get('vlcContinuationCallbackState');
    Object labels = inputMap.get('vlcContinuationCallbackLabels');
  5. Utilice el mƩtodo OmniContinuation.getResponse para recuperar la respuesta.

    Clase de ejemplo 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;
        }
    }
 
Cargando
Salesforce Help | Article