- 05 Sep 2025
- 5 Minutes to read
- Print
- DarkLight
Example 7: Messaging Flow A
- Updated on 05 Sep 2025
- 5 Minutes to read
- Print
- DarkLight
This example should be used as a reference to understand basic concepts and ideas on integrating with Relay Network. It should not be taken literally as this is how integration to Relay must be done. You should replace your record types, field names, business logic, etc. with those that match your business process and setup.
Example 1
Whenever a Case is created or updated with a certain condition, we can trigger a message to inform the customer/service agent that the case has been picked up and the service agent is working through it/ a case has been locked. In order to make this logic work in Salesforce, we first have to utilize the custom field to see if the Contact has already been onboarded to Relay before making a call out to Relay Messaging Action through the flow. In case the contact is not already onboarded; while making a Relay messaging request, it will result in a failure in message send.
NOTE
Using an asynchronous path is always a good idea when integrating with Relay. This ensures all of your primary business logic is executed as fast as possible and prevents any issues in the Relay flow from affecting your records from being inserted or updated.
Assumptions
The user’s data is stored in a PersonAccount/Contact record
The PersonAccountID/ContactID field will be used for the Relay CCID.
We already have created a custom checkbox field, HasBeenOnboardedToRelay__c, on the person account/Contact. This field is used to determine if the user has already been onboarded to Relay. So that it can be used as a filter criteria while extracting the eligible CCIDs for sent.
TCPA consent is stored in a Person Account/contact record in a custom field called HasConsentedToSMS c, so that it can be used as a filter criteria while extracting the eligible CCIDs/contacts for sent, or we can use the RelayConsent__c field by validating if it’s not STOP.
Flow Resources
Resource Name | Type | Description |
RelayMessageRequest |
| This resource will be populated with the details about the user to whom the message is supposed to be sent. |
RelayDynamicInput |
| In this example, we will be passing the case number and case reason (assigned to the contact/person Account on the case) as a dynamic input field to Relay. Since these dynamic input fields were not onboarded before and are going to be used with RelayMessagingRequest Apex action to trigger a message, passed will only pass field names, not the value. See Relay Dynamic Inputs |
RelayMessageRequestCollection |
| When passing different CCID and other required parameters to Relay, all the fields and records must be grouped into a collection. See RelayMessageRequest |
Count |
| This variable will be used as a counter variable to limit the 200-batch size in each transaction while making a call to the relay for message sending. |
Flow Logic
(1) Configure the Start Element
Create a Scheduled-Triggered Flow.
Pull the Get Record data element from Canvas.
Set any specific Entry Conditions as per your business logic. For example, we can include the following conditions:
Ensure the SMS TCPA consent value is not Stop.
Ensure the PersonMobilePhone field is not null.
Including Call_Response c is either of these (‘Unresponsive 1st Attempt’, ‘Unresponsive 2nd Attempt’,’Unresponsive 3rd Attempt’) to send the customer follow-up message when calls are not being picked up by the customer.
How Many Records to Store - Pick All records.
How to Store Record Data – Pick Automatically store all fields
(2) Looping through all the Records:
Pull the logic loop activity from Canvas
Select the collection Variable as Cases from Get Records
Specify Direction for Iterating Over Collection from First item to last item.
(3) Populate the Messaging Request Resource
Add an Assignment element to populate our MessagingRequest resource
Set the values for the MessagingRequest resource as follows:
{!RelayMessagingRequest.ccid} Equals {!Loop_through_Case.CCID c}
{!RelayMessagingRequest.triggerId} Equals {TriggerID from CXB}
{!RelayMessagingRequest.id} → {!Loop_through_Case.Id} {This one is required when using a dynamic input parameter in the message}
{!Count} Add 1
{!RelayMessagingRequest_collection} Add {!RelayMessagingRequest}
(4) Populate the input_field data and add fields to the Collection:
We will be adding a custom Input_ field to the Relay Messaging request. This Input_ field will contain the number of the case and the reason why the case was locked, The field value will be extracted and passed to relay along with other details to interpret the final message along with a dynamic parameter before being sent out to the end customer. Input resources are passed to the Relay Messaging Action as a collection. Therefore, for each Input_ field we want to send to Relay, we have to add it to a collection.
Add an Assignment element
Add the CaseNumber, Reason fields to the collection as:
{!Relay_DynamicInputField_collection} Add CaseNumber
{!Relay_DynamicInputField_collection} Add Reason
(5) Setting up Counter Condition:
Add a Decision element
Set up the condition to run the loop only until the “Count is Less than 200” to make sure only 200 records are being added into the collection and sent through the Messaging Apex action request in one API transaction/call.
(6) Trigger the message from Relay:
Leverage the RelayMesaageRequest flow action to callout to Relay and Trigger the Message.
Add the Apex Action element and search/choose the RelayMessageAction.
Set the Batch Request value to {!RelayMessagingRequest_collection}
Set the Dynamic input_variable Names to {!Relay_DynamicInputField_collection}
Leave the TriggerID blank, as we have already added it to the assignment of the messaging request.
Turn the Send via Future ON by selecting the Value TRUE.
(7) Reset Counter:
Now we have to clear out the previous 200 records where Messages have already been triggered from the collection and prepare the inputs/assignments for another 200 Messages to send, and so on until the loop ends.
{!Count} = 0
{!RelayMessagingRequest_collection} REMOVE ALL
{!Relay_DynamicInputField_collection} REMOVE ALL
(8) Last batch Left Condition:
This condition is to make sure if there are any records left in the last batch, which are less than 200, which means it couldn’t go through with the Decision with batch size = 200, will be dealt with this decision path logic
Add a Decision element
Set up the condition “Count greater than 0” to make sure there are some records when the last batch exited from the loop after the loop got finished with total records, and then these records will be added into the collection and sent through the Messaging Apex action request in one API transaction/call as was done in previous batches.
(9) Populate the input_field data and add fields to the Collection for the last batch:
Please repeat step 4.
(10) Trigger the message from Relay for last batch left:
Repeat step 6.