---
schema_version: "1"
id: a36ce6d9ae89e8d92d4e2d431e8b2e6ebc15289fac93fdff6e3435378e075deb
title: Make a Long-Running Remote Call Using VlocityContinuationIntegration (Managed Package)
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/xcloud/264-0-0/os_make_a_long_running_remote_call_using_vlocitycontinuationintegration.md
canonical_url: https://help.salesforce.com/s/articleView?id=xcloud.os_make_a_long_running_remote_call_using_vlocitycontinuationintegration.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: 5fe56203638888759bc9e9b35119b1b686a6009e9cf6e830f0a356f26788d82f
description: For the managed package runtime, to support long-running remote calls, Vlocity supports the use of the Salesforce Continuation object. The VlocityOpenInterface2 interface and VlocityContinuationIntegration class support normal Remote Calls and Remote Calls that use the Continuation Object. For the new Apex classes, don’t use VlocityOpenInterface.
products:
  - Omnistudio
release: "264"
---
# Make a Long-Running Remote Call Using VlocityContinuationIntegration (Managed Package)

For the managed package runtime, to support long-running remote calls, Vlocity supports the use of the Salesforce Continuation object. The VlocityOpenInterface2 interface and VlocityContinuationIntegration class support normal Remote Calls and Remote Calls that use the Continuation Object. For the new Apex classes, don’t use VlocityOpenInterface.

![Managed Package app icon](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-xcloud-omnistudio_for_managed_packages-264-0-0-production-enus/aa2554ec-624a-4ee6-8da4-6435670e6e62/resources-global/_corporate/images/managedpackageicon.png) This information is for Omnistudio for Managed Packages. For Omnistudio on standard runtime, see [Omnistudio Help](https://help.salesforce.com/s/articleView?id=xcloud.os_omnistudio_standard.htm&language=en_US).

For more information on the SFDC Continuation object, see the following Salesforce documentation:

- [Process for Using Asynchronous Callouts](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_continuation_process.htm)
- [Apex Continuations: Asynchronous Callouts from Visualforce Pages](https://developer.salesforce.com/blogs/developer-relations/2015/02/apex-continuations-asynchronous-callouts-visualforce-pages)

To make a remote call using the Salesforce Continuation object and extending the VlocityContinuationIntegration class:

1. Create an Apex class that extends the VlocityContinuationIntegration class.
    
    This class implements VlocityOpenInterface2.
2. Implement the callback method in the invokeMethod. For more information, refer to the sample class at the end of this topic.
3. For the method that returns the Continuation Object, call the method VlocitySetAsyncCallbackState before the return.
    
    ```
    con.continuationMethod = 'customcallback'; // implemented in invokeMethod
    VlocitySetAsyncCallbackState(con, con.addHttpRequest(req), options);
    ```
4. For the last callback method in the chain that returns the response back to Omniscript, use the following code to get the state of the Continuation Object and system labels.
    
    ```
    Object state = inputMap.get('vlcContinuationCallbackState');
    Object labels = inputMap.get('vlcContinuationCallbackLabels');
    ```
5. The 'state' Object returned from `inputMap.get('vlcContinuationCallbackState')` must be a `Map<String, Object>` with contents that can’t be directly cast using `(CustomApexWrapperClass)inputMap.get('vlcContinuationCallbackState')`. Instead, the returned object must be serialized to JSON and then deserialized and cast to its correct class. For example:
    
    ```
    CustomApexWrapperClass wrap = (CustomApexWrapperClass)JSON.deserialize(JSON.serialize(state), CustomApexWrapperClass.class);
    ```
    
    This approach permits any data written to the VlocitySetAsyncCallbackState to be retained and used as its custom Apex class.
    
    **Sample Class VlocityContinuationIntegrationTest.cls**
    
    ```
    // Sample Apex class for making Remote Call in OmniScript
    // (1) Create a custom Apex class which extends VlocityContinuationIntegration, for a Vlocity managed package,
    // need to include the Namespace prefix - NS.VlocityContinuationIntegration
    // (2) implement invokeMethod, return type is Object (a) in the Continuation Object case, return Continuation Object
    // (b) in the normal case, you can return Boolean
    global with sharing class VlocityContinuationIntegrationTest extends VlocityContinuationIntegration
    {
    global override 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('Continuation1'))
          {
             // this returns Continuation Object
             return Continuation1(10, inputMap, outMap, options);
          }
          else if(methodName.equals('Continuation2'))
          {
             return Continuation2(8, options);
          }
          else if(methodName.equals('customcallback'))
          {
             customcallback(inputMap, outMap, options);
          }
          // other methods to handle normal Remote Call
          else
          {
             result = false;
          }
       }
       catch(System.Exception e)
       {
          // System.log ...
          result = false;
       }
       return result;
    }
    // You can have other parameters as well, but make sure you always pass in Map<String, Object> options
    private Object Continuation1(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
       Continuation con = new Continuation(60);
       //
       // Please set up callback method here
       // (1) Include this callback method in the above invokeMethod, refer to
       //     else if(methodName.equals('Continuation2'))
       // (2) methodName is CASE SENSITIVE
       con.continuationMethod = 'Continuation2';
       // The following method MUST BE CALLED
       // params:
       // (1) first parameter = Continuation Object
       // (2) second parameter = WHATEVER YOU WANT TO SET THE state parameter of the CONTINUAION Object
       //     https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_continuation_process.htm
       // (3) third parameter = options
       // what it does:
       // restructure the state property of the Continuation Object to be passed to the next Callback
       // con.state is a Map, which contains:
       // (a) vlcContinuationCallbackState - the state you want to set, in this example, con.addHttpRequest(req)
       // (b) vlcContinuationCallbackLabels - labels, refer to
       //     https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_continuation_process.htm
       VlocitySetAsyncCallbackState(con, con.addHttpRequest(req), options);
       // Return it to the system for processing
       return con;
    }
    // callback for the first Continuation
    // Returns Continuation Object
    // This is to show you how to serialize multiple long running remote calls
    private Object Continuation2(Integer count, Map<String, Object> options)
    {
       // EXAMPLE
       // 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
       Continuation con = new Continuation(60);
       // (1) This callback method should be included in the above invokeMethod, refer to above
       //     else if(methodName.equals('customcallback'))
       con.continuationMethod = 'customcallback';
       // The following line has to be called
       VlocitySetAsyncCallbackState(con, con.addHttpRequest(req), options);
       // 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 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');
       // EXAMPLE
       HttpResponse response = Continuation.getResponse((String)state);
       Integer statusCode = response.getStatusCode();
       if (statusCode >= 2000)
       {
          // System.log ...
       }
       // This goes back to OmniScript
       outMap.put('continuousResp', response.getBody());
       return null;
       }
    }
    ```