---
schema_version: "1"
id: 01acced2885bbad4cb1465eda01f9d4a3089502a3f31c3e3f29b6e45b63b34ae
title: Create a Try-Catch Block Example
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/xcloud/264-0-0/os_create_a_try_catch_block_example_49920.md
canonical_url: https://help.salesforce.com/s/articleView?id=xcloud.os_create_a_try_catch_block_example_49920.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: 6ca3ce3ce4794d4ddd94c4551b26e11067674e183d904861efd75adf9b2d15bf
description: An Integration Procedure creates and deletes a Contact with the specified LastName and returns an error message if the LastName is blank.
products:
  - Omnistudio
release: "264"
---
# Create a Try-Catch Block Example

An Integration Procedure creates and deletes a Contact with the specified LastName and returns an error message if the LastName is blank.

The Integration Procedure has these components:

- A Try-Catch Block, named TryCatchBlock1
- An Omnistudio Data Mapper Post Action, named DRPostAction1
- A Delete Action, named DeleteAction1
- A Response Action, named ResponseAction1

The Structure panel looks like this:

![The contents of the Structure panel are listed in the preceding text.](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-xcloud-omnistudio-264-0-0-production-enus/f526eaa8-ae05-487a-8944-4bb99b0b78ac/omnistudio/images/iptrycatch1.png)

To build this Integration Procedure:

1. From the Omnistudio Integration Procedures tab, click **New**.
2. Provide an **Integration Procedure Name**, a **Type**, and a **SubType**, and click **Save**.
3. Drag a Try-Catch Block into the Structure panel and give it the following settings:
    
    1. Under Failure Response, click **Add Key/Value Pair**. Set the Key to `failureResponse` and the Value to `You must provide a last name.`
    2. Make sure the **Fail on Block Error** checkbox is checked.
4. Create the Data Mapper Load that the Data Mapper Post Action component calls:
    
    1. Give it a **Data Mapper Interface Name** of `CreateContact` and an **Interface Type** of **Load**.
    2. On the Objects tab, click **Add Object** and select **Contact**.
    3. On the Fields tab, click the **+** icon and enter `LastName` as both the **Input JSON Path** and the **Domain Object Field**.
    
    If you aren't sure how to create a Data Mapper Load, see the examples in [Omnistudio Data Mapper Load Examples](https://help.salesforce.com/s/articleView?id=xcloud.os_dataraptor_load_examples_47229.htm&release=264.0.0&type=5 "Data Mapper Load examples demonstrate formulas and object relationships.").
5. Drag a Data Mapper Post Action component into the Try-Catch Block and give it the following settings:
    
    1. Set the **Element Name** to `DRPostAction1`.
    2. Set the **Data Mapper Interface** to `CreateContact`.
    3. Make sure the **Fail on Step Error** checkbox is checked.
6. Drag a Delete Action component after the Try-Catch Block. Under Delete SObject, set the **Type** to **Contact** and the **Path To Id** to `%DRPostAction1:Contact_1:Id%`.
7. Drag a Response Action into the Structure panel as the last component and check the **Return Full Data JSON** checkbox.
8. Go to the Preview tab and test the Integration Procedure:
    
    1. Under Input Parameters, click **Add New Key/Value Pair**.
    2. Set the Key to `LastName` and the Value to any name you like.
    3. Click **Execute**.
    
    The output should look something like this:
    
    ```
    {
      "response": {},
      "ResponseAction1Status": true,
      "DeleteAction1": [
        {
          "errors": [],
          "success": true,
          "id": "0034N00001rNgqqQAC"
        }
      ],
      "DeleteAction1Status": true,
      "TryCatchBlock1": null,
      "TryCatchBlock1Status": true,
      "DRPostAction1": {
        "ActualTime": 626,
        "CpuTime": 345,
        "Contact_1": [
          {
            "UpsertSuccess": true,
            "Id": "0034N00001rNgqqQAC",
            "LastName": "Aristotle"
          }
        ],
        "error": "OK",
        "responseType": "SObject"
      },
      "DRPostAction1Status": true,
      "options": {
        "queueableChainable": false,
        "ignoreCache": true,
        "resetCache": false,
        "chainable": false
      },
      "LastName": "Aristotle"
    }
    ```
9. Make the Value blank and click **Execute** again. The output should look something like this:
    
    ```
    {
      "result": {
        "failureResponse": "You must provide a last name."
      },
      "success": false
    }
    ```