Your First Flow
This is a simple flow that will send you an email. The purpose of this flow is to get you started building flows and demonstrate how steps interact with one another.
Your account must have flow author permission 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 .
Add a new property by clicking the plus sign under the Value field of 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.
Notice that the Step Detail section looks different than the Map JSON List or Object step. This section will change depending on the step type selected.
Change the Emails field to an expression by selecting the first icon.
5. 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, look at 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’s output will be an array of objects even if there is only one or none.
[emailAddress] refers to the property we want to use the value from.
6. Skip the Attachment section. You can include a single attachment on an email step, but we aren’t going to use it in the sample flow.
7. 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.
8. Select Save at the bottom of the step window.
Save and Run the Flow
Select Save and Deploy to Staging.
Choose Run in the upper right corner.
Select Run in the Run Flow? window. App Xchange brings you to the Runs tab of the flow with your flow in the Queued status.
Choose 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 should see the email in your inbox.
In App Xchange, click anywhere on the Success line to see the Run Details page. The header section lists various statistics of the flow run. You should see that one email was sent.
Select 1 Email Sent to see 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 we’ll 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.
From the Edit tab of the flow you just created, select Manage Configurations, directly below the Edit tab name.
Select Add Configurations.
Set the following values
Key = emailAddresses
Title = Email Addresses
Description = One or more email addresses
Required = leave unchecked
Type = Select Multiple Text Items from the drop down
Leave the remaining fields blank
Choose Save at the bottom of the window.
Select Save and Deploy to Staging.
6. Select the Configure icon in the upper right.
7. Select the blue plus sign and enter your email address in the box. Select the blue plus again if you want to add more than one email address.
8. When you are finished adding email addresses, choose Save.
9. Select X to exit this window.
10. Select the Send Email step.
11. 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.
12. Select Save at the bottom of the window.
13. Choose Save and Deploy to Staging.
14. Select Promote to Main.