Use Orchestrations to Implement Business Logic

Learning Objectives

After completing this unit, you’ll be able to:
  • Summarize what an orchestration is.
  • Explain what states, rules, and actions are.
  • Create a variable.
  • Use actions to create a case.

Orchestrations Carry Out the Business Logic

Now let’s see how to set up the business logic that applies to your data.

An orchestration is a combination of states, rules, actions, and transitions that carry out your business logic and create engaging experiences for your customers. For Radical Routers, our orchestration monitors the health of the routers and takes actions when particular events happen under specified conditions. Specifically, our orchestration monitors the heartbeat of the routers. And when the heartbeat becomes low or irregular for a certain period of time, a Service Cloud case is created automatically.

We use the sketch and the table we created in the first unit to guide our Salesforce IoT solution for Radical Routers. But before we look at those, let’s take a little detour to review some key terms. There’s a lot going on in orchestrations, and it helps if you understand all the different components before you start composing.

When we say We mean
State The status and collection of rules that apply to objects or people. For example, Radical Routers has three states: Healthy, Error, and Warning.
Rule The logic that tells an orchestration what to do. Rules are made up of events, conditions, actions, and, optionally, transitions.
Event Real-time events or periods of time that trigger a rule to be evaluated, for example, an irregular heartbeat signal from a router.
Action The part of a rule triggered by an event, for example, creating a service case.
Condition Additional criteria used within a rule. Conditions must be met for a rule to fire.
Transition A move from one state to another, initiated by a triggering event or condition.

Phew! That’s a lot of terms, but our use case can help you learn more about each part.

Let’s go back to our sketch.

Diagram of the Healthy, Warning, and Error states with arrows from Healthy to Warning, Warning to Healthy, Warning to Error, and Error to Healthy.

The circles represent the states in our orchestration, which we call Router Health and Proactive Service. When our data runs through the orchestration, the events determine what state the devices are in and trigger actions and transitions based on the rules you set up.

Now it’s time to build our orchestration.

Create the States

Our simple use case has these three states: California, Rhode Island, and Hawaii. Just kidding! States in orchestrations don’t mean those kind of states.

Our use case has these three states: Healthy, Warning, and Error. (Now, that makes much more sense.) You can create the states either in the States view or Rules view of the Orchestrations tab. This is what the States view of our Radical Routers orchestration looks like.

States view of an orchestration showing three states: Healthy, Warning, and Error.

We used the States view (1) tools (2) to create the states and add the transitions (3). Salesforce IoT automatically creates the nice colors and flowy arrows for you.

The States view simply shows you the states and transitions. It’s like a sketch within Salesforce IoT. This lets you iterate until you have things set up the way you want. You add the rules, global rules, and variables in the same named views on the Orchestrations tab.

Orchestrations tab of Thunder showing Rules, Global Rules, and Variables view tabs.

Now we’re ready to create the rules, which add meaning to our orchestration. Rules make the orchestration act on the data that flows through the orchestration.

Write the Rules

A list of places to visit is fun to put together. But without the details of how to get from town to town, the list doesn’t do much for you. Similarly, the States view of our orchestration looks pretty, but it’s meaningless without the specifics of how the devices move from state to state. The rules provide those specifics and give meaning to your orchestration.

As a reminder, rules are the logic that tells an orchestration what to do. Rules are made up of events, conditions, actions, and, optionally, transitions.

Before we write our radical rules for our Radical Routers orchestration, let’s keep a few things in mind and follow these best practices, or rules of thumb.

  • You can define as many states as you need for your orchestration, and states can contain any number of rules. But it’s best to start small and build from there. This lets you test and iterate easily along the way as necessary.
  • Use meaningful names and descriptions when adding states and rules. This makes it easier to identify them and for others to understand your logic.
  • When you create your rules, use the same expression syntax you use when creating formula fields.
  • Use a global rule to apply a rule to all states at all times.
  • Consider using variables. A variable is a container for data used in an orchestration. Use variables to create shortcuts for repeated actions. Variables are not required for orchestrations, but they can be helpful.

Are you ready to make your routers super radical? Let’s write the rules that put this orchestration to work. Oh, and your customers will feel radical too.

Step 1. Create a Variable As an Irregular Heartbeat Counter

Before we start writing rules, we create a counter variable to measure when the router heartbeat is irregular.

The “irregular_heartbeat” field value in the router event is “FALSE” if the heartbeat signal is normal. When the signal becomes irregular, the event has an “irregular_heartbeat” value of “TRUE”.

Variables list with “irregular_heartbeat_counter”.

We’ve created a variable called “irregular_heartbeat_counter” (1) that counts (2) when the value of the “irregular_heartbeat” field equals “TRUE” (3). We use this variable in rules that transition routers to other states based on the value of the variable. Notice that we added a meaningful description (4) that is helpful not just to us, but to others who may need to modify the orchestration later.

Step 2. Create the Rules of the Healthy State

Under each state, you define the rules that apply to the device in that state.

The Healthy state is the default state. When the router data enters the orchestration, the routers start in the Healthy state and remain there until the heartbeat becomes irregular for three or more events. When this happens the router transitions to the Warning state. This rule has no actions; just a transition to another state.

Healthy state rules.

This is what the rule looks like set up in Salesforce IoT. (1) This rule says that when the router event (event) (2) irregular heartbeat count is greater than or equal to 3 (condition) (3), the router transitions to the Warning state (transition) (4).

Step 3. Create the Rules for the Warning State

When a router enters the Warning state, it remains there until one of two rules apply.

Warning state rules.

The first rule says that if after 2 minutes the irregular heartbeat count is less than or equal to 10 (condition), then the irregular heartbeat counter resets (action) and the router transitions back to the healthy state (transition) (1).

The second rule says that if at any time the irregular heartbeat count is greater than 10 (condition), then the router transitions to the Error state (transition). At the same time, a case is created in Service Cloud by setting up an output (action) (2).

Step 4. Create the Rules for the Error State

When the router enters the Error state, it stays there until the irregular heartbeat value equals FALSE, at which point the irregular heartbeat counter resets, and the router transitions back to the Healthy state. Once in the Healthy state, the same rule applies to the router as it does to all other routers in the Healthy state.

Error state rules.

Our Radical Routers use case is a simple orchestration that we used to make it easy to understand how things work. But what’s cool is that there are endless possibilities with the rules and actions we can take. In Salesforce IoT, it’s easy to create and modify the states and rules to fine-tune your orchestration to exactly what you want.

The rules are in place! Let’s make our first move to put this orchestration in action.

retargeting