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

Pages

Step 5: Callout Template Response Actions (Old Interface)

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.

 

Update Main Record

This is the main response action type. You can only define one of them. If you select this checkbox, 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 ‘Add Field’ and you will see a list of fields from the Main Object to update.

 

In the Type dropdown, you can see the available options for 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 JSON Mapping will allow you to update the field with a value from the Response Body JSON:
    • image48
  • Formula: This allows you to build a formula using values from the response body. 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.
  • Custom Setting: This allows you to map a field from a Hierarchy or List Custom Setting record.

 

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.

pasted-image-0-5

 

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 ‘Add Field,’ 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.

pasted-image-0-6

 

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 record” 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 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.

pasted-image-0-7

 

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.

pasted-image-0-8

 

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. Additionally, you can use the “Set Only On New Records” checkbox to limit some of the mapping to the create action only.

 

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.

pasted-image-0-9

 

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.

 

Response Action Criteria

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 scrolling down to the “This Action Runs” section and click on “[Customize]

pasted-image-0-10

 

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

pasted-image-0-11

 

Once you have completed your actions mapping, scroll to the top of the page and press ‘Save’ to complete your Callout Template.

 

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.