Skip to main content

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 new or updated closed-won opportunities in Salesforce with sales orders in NetSuite.

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 sketch out the steps of the flow using a flowchart. You can do this using paper and pencil to get a good idea of what your flow will look like.

Here’s an example flowchart showing all the steps of an integration flow for the NTO use case described in the previous unit.

Flowchart for the integration flow for NTO use case.

Here’s a detailed description of the tasks and their associated flow components to create a flow for this NTO use case.

Task Flow Components

Find any new or updated closed-won opportunity in Sales Cloud.

Trigger from Sales Cloud on new or updated opportunity that meets the conditions the stage is closed won and the NetSuite order ID is empty. The latter condition checks that no matching sales order exists in NetSuite, thus ensuring no duplicate sales orders are created.

Fetch the account associated with the opportunity.

Action step to get a list of accounts with the same account ID as that of the opportunity in Sales Cloud.

Get all opportunity products associated with the opportunity.

Action step to get a list of opportunity products with the same opportunity ID as that of the opportunity in Sales Cloud.

Perform these tasks.

  • Create a sales order for the account in NetSuite.
  • Update the opportunity in Sales Cloud.

Use a For Each block to iterate over the list of accounts. 

In the For Each block:

  • Action step to create a sales order with all the opportunity products in NetSuite.
  • Action step to update the opportunity with the sales order’s internal ID in Sales Cloud.

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.

Note

If you have a large integration task, it’s recommended that you break up the task into manageable, bite-sized chunks, and then create a flow for each chunk. This enables you to more easily and quickly build, test, and run your flows to accomplish the task.

Take a look at this video demonstration showing how to connect Salesforce to NetSuite using MuleSoft Composer.

Design a Flow

Now, you’re ready to design an integration flow that syncs new or updated closed-won opportunities in Salesforce with sales orders in NetSuite.

Note
The solution to this flow appears at the end of this section. If you have any issues with designing your flow, refer to the solution flow for guidance.

Follow these steps to design a flow.

Launch MuleSoft Composer from the NTO org.

  1. Log in to your NTO org using your username and password.
  2. From the App Launcher, enter Composer and select MuleSoft Composer.

Create a new flow.

  1. Click Create New Flow.
  2. Click the pencil icon next to the default flow name.
  3. Name the flow Sync Salesforce Opportunities to NetSuite Sales Orders and click Save.

Create a trigger for the flow using an NTO sandbox org connection.

  1. Click Salesforce.
  2. 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.
  3. Name the connection NTO sandbox org.
  4. 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.
  5. Enter your NTO sandbox org’s username and password and click Log In to Sandbox.
  6. 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 first step (trigger) of the flow appears.

Configure the trigger to start the flow every time an opportunity is created or updated in the NTO org.

  1. Click in the Choose an event that starts this flow field and select New or updated record.
  2. In the Object Type field, enter Opportunity.
  3. In the Conditions to filter the objects picklist, select All conditions must be met (AND).
  4. Select Stage as the field, Equals as the operator, and enter Closed Won as the value.
  5. Click Add a condition, and then select NetSuite Order ID as the field and Is Empty as the operator.
  6. Look at the Sample Output section, which shows fields and associated sample values from a closed-won opportunity in the NTO org. This confirms you’re connected to the correct org and lets you know the structure of the data that is available in later steps of your flow.
    Step 1 of flow as trigger event with conditions for Stage and NetSuite Order ID.
  7. Click Save to save the flow.

Create the second step for the flow using the existing NTO sandbox org connection.

  1. Click the plus icon to add a step.
  2. Click Salesforce, and then click NTO sandbox org.
    Note: You reuse the existing NTO sandbox org connection.

Configure the second step to get all the accounts with the same account ID as that of the triggering opportunity.

  1. Click in the Action field and select Get records.
  2. In the Object Type field, enter Account.
  3. In the Conditions to filter the objects picklist, select All conditions must be met (AND).
  4. Select Account ID as the field, Equals as the operator, and Account Id from step 1 of the flow as the value. This selects the account associated with the opportunity. Remember that every opportunity in Salesforce is associated with an account.

Create the third step for the flow using the existing NTO sandbox org connection.

  1. Click the plus icon to add a step.
  2. Click Salesforce, and then click NTO sandbox org.

Configure the third step to get all the opportunity products with the same opportunity ID as that of the triggering opportunity.

  1. Click in the Action field and select Get records.
  2. In the Object Type field, enter Opportunity Product.
  3. In the Conditions to filter the objects picklist, select All conditions must be met (AND).
  4. Select Opportunity Id as the field, Equals as the operator, and Opportunity ID from step 1 of the flow as the value.

Create and configure a For Each block to iterate over the list of accounts.

  1. Click the plus icon to add a step.
  2. Scroll down and click For Each.
  3. In the Input list field, select List of Account from step 2 of the flow.

Create the fourth step for the flow within the For Each block using an NTO NetSuite connection.

  1. Click the plus icon to add a step within the For Each block.
  2. Click NetSuite.
  3. Click Add new NetSuite connection.
    Note: If this is your first NetSuite connection, this option doesn’t appear. Go to the next step.
  4. 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 fourth step of the flow appears.

Configure the fourth step to create a sales order containing all the associated opportunity products in NetSuite.

  1. Click in the Action field and select Create Record.
  2. In the Type of Record field, enter SALES_ORDER.
  3. Click Select Optional Fields.
  4. Using the search field, locate and select the following fields, and then click Apply. Another field called Item List is automatically added to Record > Item List > Item. This is the NetSuite list of line items that you map to the Salesforce list of opportunity products.
    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 Apply.
    • Record > ExternalId
    • Record > Tran Date
    • Record > Entity > InternalId
    • Record > Entity > Name
    • Record > Item List > Item
      • Amount
      • Description
      • Gross Amt
      • Quantity
    • Record > Item List > Item > Item > InternalId
    • Record > Item List > Item > Item > Name
  5. Map the Sales Order fields to their corresponding fields captured in the preceding steps of the flow as follows.
    • Record > ExternalId = Opportunity ID from step 1
    • Record > Tran Date = Last Modified Date from step 1
    • Record > Entity > InternalId = NetSuite Customer ID from step 2
    • Record > Entity > Name = Account Name from step 2
    • Record > Item List > Item
      • Item List = List of Opportunity Product from step 3
      • Amount = Total Price from step 3
      • Description = Line Description from step 3
      • Gross Amt = List Price from step 3
      • Quantity = Quantity from step 3
    • Record > Item List > Item > Item > InternalId = Product Code from step 3
    • Record > Item List > Item > Item > Name = Opportunity Product Name from step 3

Create the fifth step for the flow within the For Each block using the existing NTO sandbox org connection.

  1. Click the plus icon to add a step within the For Each block.
  2. Click Salesforce, and then click NTO sandbox org.

Configure the fifth step to update the triggering opportunity with its associated sales order’s internal ID in Sales Cloud.

  1. Click in the Action field and select Update record.
  2. In the Object Type field, enter Opportunity. The Opportunity ID is automatically selected because it’s a required field.
  3. Click Select Optional Fields.
  4. Use the search tool to select NetSuite Order ID and click Apply.
  5. Map the Opportunity fields to their corresponding fields captured in the preceding steps of the flow as follows.
    • Opportunity ID = Opportunity ID from step 1
    • NetSuite Order ID = Internal ID from step 4
  6. Save the flow. Your entire flow should look like this.
    Step 1 of flow showing a new or updated opportunity in Salesforce as the trigger with the conditions stage equals closed won and NetSuite Order ID is empty.Step 2 of flow to get all accounts with condition account ID equals account ID in step 1 of flow.Step 3 of flow to get all opportunity products with condition opportunity ID equals opportunity ID in step 1 of flow.For Each block to loop over list of accounts.Step 4 within For Each block to create a sales order with fields such as transaction date and name.Rest of step 4 of flow with fields such as list of opportunity products, amount, gross amount, and quantity.Step 5 of flow within For Each block to update opportunity with NetSuite sales order’s internal ID.

Good job! In the next unit, you learn how to test your flow to ensure it works as expected.

Keep learning for
free!
Sign up for an account to continue.
What’s in it for you?
  • Get personalized recommendations for your career goals
  • Practice your skills with hands-on challenges and quizzes
  • Track and share your progress with employers
  • Connect to mentorship and career opportunities