documentation logo
All you’ll ever need to know about Declarative Webhooks and how to get started.

Pages

Step 5: Callout Template Response Actions

Define Response Actions

Here you will define what actions to take based on received response. We have provided you with a guide on how to use each of these response action types.  

Click on the “+” icon on the right side to add new actions. You will be able to select the type of action you want to take.

Update Main Record

This is the main response action type. Using this action, you will be able to update the record this callout started from, based on the response. To select which fields you want to update, click on ‘”+”icon under “Field Mapping”.

You will be able to search from a list of fields from the Main Object to update.

In the “Source” dropdown, you can see the available options to map into that field.

  • If you choose Static Value, the field will be updated with that exact provided value every time the callout is made. You can provide the specific value in the “Value” field. This is useful if you want to set a status or a flag on the record.
  • Selecting Response Body Node will allow you to update the field with a value from the Response Body:
    • Click on the Edit icon at the right of the Value input to select a response body node to use to map into the field
    • If you encounter a list, you also have the option to add a filter on that list BEFORE clicking on “Select Node”. If you set the filter and it’s part of the JSON path, the filter will be included in the selected path and will be applied when the node is saved in the field.
  • Formula: This allows you to build a formula using values from the response body.
    • Click the Edit icon to edit the formula. See more details in the “Using Formulas” section of this user guide.
  • Custom Metadata: Custom Metadata: This allows you to map a field from a Custom Metadata Type record into the record field.
    • Click on the Edit icon to select a custom metadata value
  • Custom Setting: This allows you to map a field from a Hierarchy or List Custom Setting record.
    • Click on the Edit icon to select a custom setting value
  • Identify Record by External Id: When updating a field that is a lookup, you have the option to associate it with a record using an external ID field. By selecting this option, you can choose a field from the object being looked up to and a node from the response body. During the call, the template will attempt to find the record for the lookup by matching the specified field with the value from the corresponding node in the response body.

 

Create New Record

Here you have the option to create a related or unrelated record to the Main Object. You can select the object type you want to create and choose how it’s related to the main object.

Let’s say you wanted to create a Task whenever a response is received from your external system. To create a task associated with the Account Main Object, you would choose Task as your Object Type and WhatId in the Related To dropdown.

Further, if you select the “+” icon, you can map additional fields in your record creation. In our Task record example, we can map various fields associated with tasks in this create new record option.  

Update Related Record

This option enables you to update a related record to your Main Object. If Contact was your main object, you can use this to update the Account that the object is related to after the callout is made. Similar to the previous options, you have the ability to map fields associated with your related record here.

Upsert Single Record

This option enables you to find and update a record that can be identified by matching a Salesforce field with a node value. If no record is found, then you have the option to create it.

If you select a value in the “Related to the main object” input, only the records related to the main record are searched for, and if a record needs to be created, it will be linked to the main record.

Just like the other actions, you can map fields from the response body, static values, formulas or custom metadata/setting. Additionally, you can use the “Only on Insert” checkbox to limit some of the mapping to the create action only.

Upsert List of Records

This option enables you to update a list of records based on a JSON list from the response. Each record can be identified by matching a Salesforce field with a node value. If no record is found for each list item, then you have the option to create it.

If you select a value in the “Related to the main record” input, only the records related to the main record are searched, and if a record needs to be created, it will be linked to the main record.

You first need to select a JSON list from the response by clicking on “Select” next to “Mapped From JSON List”. After selecting a JSON list, choose how to identify each record by selecting a Salesforce field and a JSON node from inside the JSON list.

Just like the other actions, you can map fields from the JSON response or static values. Additionally, you can use the “Set Only On New Records” checkbox to limit some of the mapping to the create action only.

Create / Update File

This option enables you to create or update an Attachment or a File (ContentDocument) based on the response.

First, you need to select what type of record you want to create: File (ContentDocument) or Attachment. After selecting, you will be able to choose the field and node used to identify an existing record to update, in case you want to update an existing file or attachment. Then you can map fields from the JSON response or static values.

Run Autolaunched Flow

This feature allows you to utilize the capabilities of an “Autolaunched Flow (No Trigger)” flow to perform complex calculations and logic beyond basic record insertions and updates.

The process begins by selecting a flow. If the flow requires input variables, a list will be displayed for mapping. These inputs can be either the main record ID or individual values from the response body. Upon successful completion of the callout, the flow will be executed using the mapped input values. Only active Autolaunched flows without trigger are available.

Run Apex

This option enables you to run an apex class as a response action.

The class you enter needs to be a global class that extends the d_wh.ResponseActionCallable abstract class and implements the void Run(List<Id> mainRecordIds, Integer responseCode, Object parsedJSON) method.

Below is an example class that can be used as a “Run Apex” response action.

global class TestCallable extends d_wh.ResponseActionCallable {

    global override void Run(List<Id> mainRecordIds, Integer responseCode, Object parsedJSON) {

        // Add code to handle response

    }

}

The mainRecordIds parameter contains the list of ids of the used record(s).

  • If the template has no main object, this will be an empty list.
  • If the template has a main object, and ‘One Record’ is selected, this list will contain one value, the Id of the main record.
  • If the template has a main object and ‘Batch’ is selected, the list will contain all the Id of all the records used.

The responseCode parameter contains the response code received from the server.

The parsedJSON parameter contains the response body deserialized as untyped, using JSON.deserializeUntyped. That means it will be a List<Object> if the response body is a JSON list or a Map<String, Object> if the response body is a JSON object.  

 

Setting the conditions for an action to run

For each response action, you have the option to select if the action will run. By default, the actions will run if the request is successful (response code between 200 and 299). You can customize that by clicking inside the “This action runs if” input.

It will open a popup where you can add criteria.

Here, you can specify the response codes this action should run for, as well as custom criteria from the response body.

 NOTE: You can change the order of your actions by clicking on the arrows to the right of each action. The actions will run in the order you have defined them.

Additional Considerations

If you are mapping values into Date or DateTime fields, the received value needs to be in the standard yyyy-MM-dd format for Date fields or yyyy-MM-ddTHH:mm:ss.sssZ format for DateTime fields.