---
schema_version: "1"
id: ed18f7a357dcf257267d1cc1b38d5dd199860cb1137962f956afa8d8558b7d20
title: Calling Apex from Omniscripts with the Remote Action
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/xcloud/264-0-0/os_remote_action_13618.md
canonical_url: https://help.salesforce.com/s/articleView?id=xcloud.os_remote_action_13618.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: f78a602607444842e9d30cbb03c22dad34fd4556f099663002e407f6a15eb213
description: Call Apex classes from Omniscript using the Remote element, and use the Omniscript's JSON as input.
products:
  - Omnistudio
release: "264"
---
# Calling Apex from Omniscripts with the Remote Action

Call Apex classes from Omniscript using the Remote element, and use the Omniscript's JSON as input.

Before you begin, create an Apex class in Salesforce to call from Omniscript. Include the ID in the SOQL query. That field is required because the Apex class retains the queries and serializes data according to what’s actually executed.

1. Add a **Remote** element before a Step, in a Step, or after a Step to load data or send data in the Omniscript.
    
    The Omniscript's data JSON is sent as the input.
2. In the **Remote Class** field, enter the name of the Apex class that the action calls.
3. In the **Remote Method** field, enter a method of the class that the action calls. For example—`validateAddress`.
4. If required, enable the subordinate Integration Procedure that calls long-running actions to use Apex continuations.
5. In the **Pre-** and **Post-Transform Omnistudio Data Mapper Interface**—optionally select a Data Mapper Transform interface to run before or after the Remote Action.
    
    See [Omnistudio Data Mappers](https://help.salesforce.com/s/articleView?id=xcloud.os_omnistudio_dataraptors_45587.htm&release=264.0.0&type=5 "Use Omnistudio Data Mappers to declaratively retrieve, write, and modify data between Salesforce and other Omnistudio components. While you can process data with custom code (such as Apex classes), Omnistudio Data Mappers are faster to build, easier to update, and simpler to manage. They’re also reusable, helping you to move solutions quickly from development to production.").
6. Change the amount of time before the action times out using the Remote Timeout property. In the element, click **Edit Properties as JSON**, and in the `remoteTimeout` property, set a time in milliseconds.
    
    The default timeout is `30,000`, or 30 seconds. The maximum is `120,000`, or 120 seconds.
7. Configure additional properties in the Remote Action.
8. Select the response behavior of the action by selecting an **Invoke Mode**.
    
    - Default — Blocks the UI with a loading spinner.
    - Non-Blocking — Runs asynchronously, and the response is applied to the UI. Pre and Post Omnistudio Data Mapper transforms and large attachments aren’t supported. When Invoke Mode is set to non-blocking, elements using default values won’t receive the response because the element loads before the response returns. To map the response to an element, you must set Response JSON Node to VlocityNoRootNode and Response JSON Path to the name of the element.
    - Fire and Forget — Runs asynchronously with no callback to the UI. Pre and Post Data Mapper transforms and large attachments aren’t supported. A response will still appear in the debug console but won’t be applied to the Data JSON.
9. When Invoke Mode is set to non-blocking, elements using default values will not receive the response because the element loads before the response returns. You must configure these properties to map the response to an element:
    
    - **Response JSON Node**: VlocityNoRootNode
    - **Response JSON Path**: The name of the Omniscript Element receiving the value.

![Troubleshooting Omniscript](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-xcloud-omnistudio-264-0-0-production-enus/f526eaa8-ae05-487a-8944-4bb99b0b78ac/images/icon_example.png)

Troubleshooting Omniscript

In the Troubleshooting Omniscript, the callOut1 Remote Action element calls an external system to check if the asset is still under warranty. This example references the Troubleshooting Omniscript and the `OmniCallout` and `DataObjectService` Apex classes.

It implements the Remote `OmniCallout` class and the remote `checkWarrantyStatus` method. Since this is a sample Omniscript, the method contains a hard-coded response:

![image](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-xcloud-omnistudio-264-0-0-production-enus/f526eaa8-ae05-487a-8944-4bb99b0b78ac/omnistudio/images/salesforce_apexclassdetail_omnicallout.png)

The callOut2 Remote Action calls the `returnItemOrder` method, which in turn calls the `DataObjectService` class that calls out to a Heroku instance to return an order number:

![image](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-xcloud-omnistudio-264-0-0-production-enus/f526eaa8-ae05-487a-8944-4bb99b0b78ac/omnistudio/images/salesforce_apexclass_dataobjectservice.png)

The following class structure can be used to call out to an external system:

`global with sharing class CustomClassName implements NS.VlocityOpenInterface    {      global CustomClassName() {} 			     global Boolean invokeMethod(String methodName, Map<String,Object> inputMap, Map<String,Object> outMap, Map<String,Object> options) { 			               Boolean result = true; 			       try{ 			              if(methodName.equals('customMethodName')){ 			              // your implementation, use outMap to send response back to OmniScript                                                                   			             } 			             }    	else if(methodName.equals('customMethodName2')){ 			             // your implementation, use outMap to send response back to OmniScript                    			          }                               			       } catch(Exception e){ 			                     result = false; 			               } 			               return result; 			          } 			 }`