Design a Flow
Learning Objectives
After completing this unit, you’ll be able to:
- Prepare to design a flow.
- Design a flow to automatically sync updated inventory items in NetSuite with products and associated price book entries in Salesforce.
Prepare to Design a Flow
Recall from MuleSoft Composer Basics that a flow is a sequence of steps that you assemble and configure to integrate systems and data. Before designing a flow, you should map the tasks your flow must perform to their corresponding steps in the form of flow components. You can do this using paper and pencil so you can get a good idea of what your flow will look like.
Here’s an example of such mappings for the NTO use case described in the previous unit.
Task | Flow Components |
---|---|
Find any updated inventory item in NetSuite. |
Trigger from NetSuite on updated inventory item. |
Fetch a corresponding product, if any. |
Action step to get all products in Sales Cloud whose NetSuite item ID is the same as the inventory item’s internal ID. |
Determine if a corresponding product exists in Sales Cloud. |
If/Else block evaluating if the list of products is empty, meaning the product doesn’t exist in Sales Cloud. |
If a corresponding product doesn’t exist |
Within the If block:
|
If a corresponding product exists |
In the Else branch of the If/Else block:
|
By default, MuleSoft Composer validates your work and provides contextual in-app help every step of the way. For example, when you add a connection to a system, MuleSoft Composer tests the connection to make sure it works before you can proceed to the next step. Also, to simplify building your flows, MuleSoft Composer prompts you to complete required fields within each step.
As a best practice, when building a flow, add a few steps and test iteratively until you complete the flow.
Design a Flow
Now, you’re ready to design an integration flow that syncs updated inventory items in NetSuite with products and associated price book entries in Salesforce.
Follow these steps to design a flow.
Launch MuleSoft Composer from the NTO org.
- Log in to your NTO org using your username and password.
- From the App Launcher, enter
Composer
and select MuleSoft Composer.
Create a new flow.
- Click Create New Flow.
- Click the pencil icon next to the default flow name.
- Name the flow
Sync NetSuite Inventory Items to Salesforce Products and Price Book Entries
and click Save.
Create a trigger for the flow using the NetSuite connection.
- Click NetSuite.
- Click Add new NetSuite connection.
Note: If this is your first NetSuite connection, this option doesn’t appear. Go to the next step. - Using the text file that contains the NetSuite connection parameter values, enter the required values with
NTO NetSuite
as the connection display name, and then click Create. MuleSoft Composer automatically tests the connection. If no error message appears, you have a successful connection, and the first step (trigger) of the flow appears.
Configure the trigger to start the flow every time an inventory item is updated in NetSuite.
- Click in the Choose an event that starts this flow field and select Updated Record.
- In the Type of Record field, enter
INVENTORY_ITEM
. - Click Save to save the flow.
Create the second step for the flow to get all products in Salesforce that match the triggering inventory item.
- Click the plus icon to add a step.
- Click Salesforce.
- Click Add new Salesforce connection to create a connection to the NTO sandbox org.
Note: If this is your first Salesforce connection, this option doesn’t appear. Go to the next step. - Name the connection
NTO sandbox org
. - Select the checkbox This is a sandbox organization and click Create.
Note: If you use a developer org, skip selecting this checkbox and click Create. - Enter your NTO sandbox org’s username and password and click Log In to Sandbox.
- Click Allow to grant MuleSoft Composer the permissions to access the identity URL service, manage user data via APIs, and perform requests at any time. MuleSoft Composer automatically tests the connection. If no error message appears, you have a successful connection, and the second step of the flow appears.
Configure the second step to get all products that match the inventory item.
- Click in the Action field and select Get records.
- In the Object Type field, enter
Product
. - In the Conditions to filter the objects picklist, select All conditions must be met (AND).
- Select NetSuite Item ID as the field, Equals as the operator, and Record > InternalId from step 1 of the flow.
Create and configure an If/Else block to evaluate whether the inventory item has a corresponding product.
- Click the plus icon to add a step.
- Scroll down and click If/Else Block. The All conditions must be met (AND) condition is selected by default.
- Select List of Product from step 2 of the flow as the field and Is empty as the operator. If this condition is met, it means the inventory item doesn’t have a corresponding product in Sales Cloud. So the next three steps in the If branch (create Salesforce product, update NetSuite inventory item, and create Salesforce price book entry) are executed.
Create the third step for the flow within the If branch of the If/Else block to create a product in Sales Cloud.
- Click the plus icon to add a step within the If branch.
- Click Salesforce and then click NTO sandbox org.
Configure the third step to create a product, including the inventory item’s internal ID, in Sales Cloud.
- Click in the Action field and select Create new record.
- In the Object Type field, enter
Product
. The Product Name is automatically selected because it’s a required field. - Click Add Fields.
- Using the search field, locate and select the following fields, and then click Add.
Tip: Enter a keyword for a field you want to search and then select the relevant field that appears. Clear the keyword and repeat the process for the next field. When done with selecting all fields, click Add.- Active
- NetSuite Item ID
- Product Code
- Product Description
- Map the Product fields to their corresponding Inventory Item fields captured in step 1 of the flow as follows.
- Product Name = Record > Display Name
- Active =
true
- NetSuite Item ID = Record > InternalID
- Product Code = Record > Item ID
- Product Description = Record > Purchase Description
Create the fourth step for the flow within the If branch to update the inventory item with its associated product ID.
- Click the plus icon to add a step to the If branch.
- Click NetSuite and then click NTO NetSuite.
Configure the fourth step to update the inventory item with its associated product ID.
- Click in the Action field and select Update Record.
- In the Type of Record field, enter
INVENTORY_ITEM
. - In the ID Type field, select INTERNAL. The Record Id is automatically selected because it’s a required field.
- Click Add Fields.
- In the search field, enter
salesforce
, select Salesforce Product ID, and then click Add. - Map the Inventory Item fields to the preceding steps of the flow as follows.
- Record Id = Record > InternalId from step 1
- Salesforce Product ID = Id from step 3
Create the fifth step for the flow within the If branch to create a price book entry for the product in Sales Cloud.
- Click the plus icon to add a step within the If branch.
- Click Salesforce and then click NTO sandbox org.
Configure the fifth step to create a price book entry for the product in Sales Cloud.
- Click in the Action field and select Create new record.
- In the Object Type field, enter
Price Book Entry
. The List Price, Pricebook2Id, and Product2Id are automatically selected because they’re required fields. - Click Add Fields.
- Use the search tool to select Active and click Add.
- Map the Price Book Entry fields to the preceding steps of the flow as follows.
- List Price = Record > Cost from step 1
- Pricebook2Id =
01s1U000005mSpYQAU
. This is the value of the standard price book obtained in unit 1. - Product2Id = Id from step 3
- Active =
true
Create an Else branch within the If/Else block to update the existing product that corresponds to the inventory item and update the associated price book entry for the product.
- From the bottom of the If/Else block, click Add Else.
Create the sixth step for the flow within the Else branch to update the existing product with its associated inventory item details in Sales Cloud.
- Click the plus icon to add a step within the Else branch.
- Click Salesforce and then click NTO sandbox org.
Configure the sixth step to update the existing product with its associated inventory item details in Sales Cloud.
- Click in the Action field and select Update record.
- In the Object Type field, enter
Product
. The Product ID is automatically selected because it’s a required field. - Click Add Fields.
- Select Active, Product Description, and Product Name, and then click Add.
- Map the Product fields to their corresponding Inventory Item fields captured in step 1 of the flow as follows.
- Product ID = Record > Custom Field List > Salesforce Product ID
- Active =
true
- Product Description = Record > Purchase Description
- Product Name = Record > Display Name
Create the seventh step for the flow to get all price book entries in Sales Cloud that have the same product ID and price book ID as those of the existing product.
- Click the plus icon to add a step.
- Click Salesforce and then click NTO sandbox org.
Configure the seventh step to get all price book entries with associated product ID and price book ID. This turns the result into a list of price book entries, enabling you to iterate over it and update the associated price book entry for the existing product in the next step of the flow.
- Click in the Action field and select Get records.
- In the Object Type field, enter
Price Book Entry
. - In the Conditions to filter the objects picklist, select All conditions must be met (AND).
- Select Product2Id as the field, Equals as the operator, and ID from step 6 of the flow.
- Select Pricebook2Id as the field, Equals as the operator, and enter
01s1U000005mSpYQAU
. This is the value of the standard price book obtained in unit 1.
Create and configure a For Each block within the Else branch to iterate over the list of price book entries fetched from step 7 of the flow.
- Click the plus icon in the Else branch.
- Scroll down and select For Each.
- In the Input list field, select List of Price Book Entry from step 7 of the flow.
Create the eighth step for the flow within the For Each block to update the associated price book entry for the existing product in Sales Cloud.
- Click the plus icon to add a step within the Else branch.
- Click Salesforce and then click NTO sandbox org.
Configure the eighth step within the For Each block to update the associated price book entry for the existing product in Sales Cloud.
- Click in the Action field and select Create or update record.
- In the Object Type field, enter
Price Book Entry
. The External ID Field to Match field automatically appears because it’s a required field. - In the External ID Field to Match field, select Price Book Entry ID. The Price Book Entry ID is automatically selected because it’s a required field.
- Click Add Fields.
- Select Active and List Price, and click Add.
- Map the Price Book Entry fields to the preceding steps of the flow as follows.
- Price Book Entry ID = Price Book Entry ID from step 7
- Active =
true
- List Price = Record > Cost from step 1
- Save the flow. Your entire flow should look like this.
Good job! In the next unit, you learn how to test your flow to ensure it works as expected.