Loading
Feature degradation | Gmail Email delivery failureRead More
Table of Contents
Select Filters

          No results
          No results
          Here are some search tips

          Check the spelling of your keywords.
          Use more general search terms.
          Select fewer filters to broaden your search.

          Search all of Salesforce Help
          Make a Long-Running Remote Call Using Omnistudio.OmniContinuation

          Make a Long-Running Remote Call Using Omnistudio.OmniContinuation

          To support long-running remote calls, Vlocity supports the use of the Salesforce Continuation object.

          Note
          Note Beginning Winter ‘23, Flexcards supports long-running calls from an Integration Procedure that has an HTTP Action or a Remote Action.

          For details about the SFDC Continuation object and the Callable interface, see the following Salesforce documentation:

          To make a remote call using the OmniContinuation object and implementing the Callable interface:

          1. Create an Apex class that implements the Callable interface.
          2. Implement the callback method in the invokeMethod. See the private Object invokeMethod code in the example.
          3. For the method that returns the OmniContinuation Object, call the Omnistudio.OmniContinuation constructor.
            OmniStudio.OmniContinuation con = new OmniStudio.OmniContinuation(120);
            con.ContinuationMethod = 'customCallback';
          4. For the last callback method in the chain that returns the response back to the Flexcard or Omniscript, use the following code to get the state of the OmniContinuation Object and system labels.
            Object state = inputMap.get('vlcContinuationCallbackState');
            Object labels = inputMap.get('vlcContinuationCallbackLabels');
          5. Use the Omnistudio.OmniContinuation.getResponse method to retrieve the response.

            Sample Class 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;
                }
            }
           
          Loading
          Salesforce Help | Article