Create Your First Flow
Follow these steps to build your first flow. This exercise aims to familiarize you with the core components of a flow and how they interact.
You must have the Flow Author account role to create a flow.
Create the Flow
Within a workspace, navigate to the Flows tab and select Add Flow. App Xchange opens the Add Flow window with Create New selected.
Provide a descriptive name for your flow. This usually includes the connectors involved and the goal of the flow.
Select Add.
Add a Trigger and Steps
Choose Add Trigger in the flow builder.
Select On-Demand for the trigger type.
Choose Save at the bottom of the window.
Add the First Step
Select Add Steps in the flow builder.
In the Name field, enter Map Variables.
Leave the ID field blank. This field is generated automatically.
Select Map JSON List or Object from the Type field drop down list. You can also enter the flow name to search for the flow.
In the List or Object field, enter return flow.trigger.data;
This code breaks down as follows:
[return] tells the engine that this is the value to output for this expression. Our code is a single line, but the expression window can hold large blocks of code.
[flow.trigger.data] refers to the trigger object. For this flow, the trigger is an empty object, but it could be defined differently to contain any object that is being cached between the systems registered to your workspace.
[;] each line ends with the semi-colon.
In the Property Name field, enter emailAddress.
In the Value field, enter return ['youremail@yourdomain.com']; and use your email address.
The square brackets denote that this is an array. You can add other email addresses by enclosing them in straight single quotes and separating the values with a comma within the brackets.
Select +Add Item to add a new property beneath the first property.
Name this new property subject.
Enter return 'Test Email'; for the value.
Add a new property and name it body.
Enter return 'Hello world'; for the value.
Select Save at the bottom of the step window.
Add the Second Step
Add a new step by clicking the plus sign under the Map Variables step you just created.
Name this step Send Email and select a step type of Email.
Change the Emails field to an expression by selecting the first icon.
4. Enter return flow.step('map-variables').output[0].emailAddress;
The code breaks down as follows:
[flow.step] is a code helper that refers to another step.
[('map-variables')] identifies the step reference. The value inside the single quotes is the step-id from the Map step. App Xchange generates the step-id automatically and ensures that each step has a unique value. If you need to check the step ID, review the step name in the Steps list. The step ID is displayed under the step name.
[output[0]] refers to the first object of the step output. Many step outputs will be an array of objects even if there is only one or none.
[emailAddress] refers to the property whose value we want to use.
5. Skip the Attachment section. You can include a single attachment on an email step, but you will not use it in the sample flow.
6. Enter return flow.step('map-variables').output[0].subject; in the Subject expression box.
enter return flow.step('map-variables').output[0].body; in the Body expression box.
7. Select Save at the bottom of the step window.
Save and Run the Flow
Select Save and Deploy to Staging.
Select Run in the upper right corner. The Run Flow? window opens.
Select Run to confirm. The Runs tab of the flow opens with your flow in the Queued status.
Toggle Auto Refetch to refresh the status every five seconds and see the results of the flow run.
Review the Flow Run
When the flow status updates to Success, you will see the email in your inbox.
In App Xchange, select the successful flow run to see the Run Details page. You will see that one email was sent.
Select 1 Email Sent to view the code version of the email.
Manage the Flow Configuration
When you hardcode email addresses in a flow step, it can be inconvenient for troubleshooting and updating the step. Now you will set up a configuration to hold one or more email addresses and modify our flow step to use those values instead of using the hardcoded email address.
Navigate to the Edit tab of the flow you just created.
Select Manage Configurations.
Select Add Configurations.
Enter the following values into the appropriate fields. Leave the remaining fields blank.
Key: emailAddresses
Title: Email Addresses
Description: One or more email addresses
Required: leave unchecked
Type: Select Multiple Text Items from the dropdown
Select Save.
Select Save and Deploy to Staging.
Select the configure icon in the upper right.
Select +Add Item and enter your email address in the field. Repeat this to add additional email addresses.
Select Save.
Select X to exit this window.
Select the Send Email step. The flow step drawer opens.
Enter return flow.config.emailAddresses; in the Emails expression box, replacing what is already in there.
In this code we add the Key from our Configuration to flow.config. Because we defined the Configuration type as Multiple Text Items, it will be interpreted as an array of strings which is what the Emails expression box expects.
Select Save at the bottom of the window.
Choose Save and Deploy to Staging.
Select Promote to Main.
Your flow is complete and deployed on the main branch. It can now be used within your workspace.