Design and Test a Flow
Learning Objectives
After completing this unit, you’ll be able to:
- Design a flow to automatically sync data from Salesforce to Twilio.
- Test your flow to ensure it syncs data as expected.
In this unit, you first learn how to use MuleSoft Composer to create a flow that automatically syncs opportunities in Salesforce with text messages in Twilio. Then, you test your flow to ensure it syncs data as expected.
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.
Take a look at this video demonstration showing how to connect Salesforce to Twilio using MuleSoft Composer.
Design a Flow
Now you’re ready to design an integration flow that automatically syncs opportunities in Salesforce with text messages in Twilio.
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 NTO Org Opportunities with Twilio Messages
and click Save.
Create the trigger for the flow using the NTO org.
- Click Salesforce.
- Click Add new Salesforce connection to create a connection to the NTO sandbox org.
- Name the connection
NTO sandbox org
. - Select the checkbox This is a sandbox organization and click Create.
- Enter your NTO sandbox org’s username and password and click Log In.
- Click Allow to grant MuleSoft Composer the permissions to access your basic information, access and manage your data, and perform requests on your behalf 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.
- Click the pencil icon next to the default step name.
- Name the step
Get opportunity
and click Save.
Configure the trigger to start the flow every time a new or updated opportunity is added to the NTO org.
- Click in the Choose an event that starts this flow field and select New or updated record.
- Click in the Object Type field and enter
Opportunity
. - Look at the Sample Output section, which displays shows and associated sample values from an opportunity in the NTO org. This confirms that you’re connected to the correct org and lets you know the structure of the data that’s available in later steps of your flow.
- Click Save to save the flow.
Create and configure an If/Else block to evaluate if the opportunity is closed won.
- Click the plus icon to add a step.
- Click If/Else Block.
- Click Add Conditions. The All conditions must be met (AND) condition is selected by default.
- Select Stage as the field and Equals as the operator, enter
Closed Won
as the value, and then click Save. If this condition is met, the next step in the If branch (send text message) is performed.
Create the second step of the flow within the If branch to handle closed won opportunities.
- Click the plus icon to add a step within the If branch.
- Click Twilio.
- Click Add new Twilio connection.
- Name the connection
NTO Twilio
. - Copy and paste the account SID and auth token from your text file, and then click Create. The NTO Twilio connection is created, and the second step of the flow appears.
- Name the step
Send text message
and click Save.
Configure the second step in the If branch to handle closed won opportunities.
- Click in the Action field and select Send Message.
- Map the following fields of the second step to their corresponding Opportunity fields captured in step 1 of the flow.
- To: Sales Manager’s Phone from step 1
- From: Twilio Phone from step 1
- Click in the Message text field and then click Custom Expression. You use this Custom Expression tool to configure a message that has both dynamic field values from the preceding steps of a flow and static text that you enter.
- Enter
Congratulations, opportunity
and select Name from step 1. - Enter
with amount $
and select Amount from step 1. - Enter
is now
and select Stage from step 1. - Enter
!
and click Done. - Save the flow. Your entire flow should look like this.
Next, you learn how to test your flow.
Test a Flow
After you’ve designed your flow, you need to test it from end to end to ensure it syncs data as expected. In general, you have up to 10 minutes to complete a test. When the test completes or 10 minutes have passed, the test stops. As a best practice, you should get all required applications and data ready for the test before starting it.
In this use case, when an opportunity is created or updated in the NTO org, it triggers the flow. So be prepared to enter or update a test opportunity in the NTO org’s Sales Cloud. If the opportunity is marked as closed won, a text message is sent by Twilio to the associated sales manager’s phone. So get ready to verify that the sales manager receives the message.
Follow these steps to test a flow.
- In the Sync NTO Org Opportunities with Twilio Messages flow, click Test. The flow goes into a read-only mode.
Note: While the test is running, if for some reason you want to stop it, click Stop Test. - Log in to the NTO org’s Sales Cloud, navigate to the Opportunities tab page, and click New.
- Add a new opportunity with the following values, and then click Save.
- Opportunity Name:
Backup Generators
- Account Name: Grand Hotels & Resorts Ltd
- Amount:
$100,000
- Close Date: one week from today
- Stage: Closed Won
- Sales Manager’s Phone: your phone
- Twilio Phone: paste the Twilio phone from your text file
- Opportunity Name:
- Go back to your flow and wait for the test to complete. If every step of the flow shows a green check mark, this indicates the flow ran successfully. Take a look at the Test Output section and see the record values you entered for the test.
- Access your phone and verify that you’ve received the text message. The message should say:
Sent from your Twilio trial account - Congratulations, opportunity Backup Generators with amount $100000 is now Closed Won!
If you have a paid Twilio account, then the phraseSent from your Twilio trial account
won’t appear.
- Repeat steps 1 through 5 to test another opportunity of your choice. Your flow should work as expected.
Good job! In the next unit, you learn how to activate, monitor, and troubleshoot your flow in the production environment.