Collect Contact Info from Your User
Learning Objectives
- Captures information from a user.
- Queries your Salesforce org for a record that matches what the user enters.
- Decides whether to update the matching record or create a new one.
- Creates or updates a record.
Introduction
This project walks you through the motions of building a simple flow. As you complete this project, don’t worry about understanding everything. Follow the instructions and observe how the various controls work in Flow Builder. By the end of this project, you’ll have a working flow. Later, you add to this flow as you complete the Flow Builder module. As you complete that module, you learn all about the flow building blocks that you use in this project. For now, gain some muscle memory as you repeat the flow-building pattern of drag or click, configure, and save. Let’s get started!
Create the Flow and Add a Screen
- From Setup, enter Flows in the Quick Find box, then select Flows.
- Click New Flow, select Screen Flow, click Next, and select Freeform.
- From the Elements tab in the toolbox, drag Screen onto the canvas.
New screen opens.
- For Label, enter Contact Info.
- The API Name is automatically set to Contact_Info.
- Click Done. The canvas now includes two items: Start and Contact Info.
- Drag the connector node at the bottom of Start onto Contact Info. The two canvas items are now connected.
- Click Save, and enter these values.
Field Value Flow Label New Contact Flow API Name New_Contact - Click Save.
- Throughout this project, if warnings appear, ignore and close them when you save the flow. You can always read warnings later by clicking
.
Create a Record Variable for the Contact
Because you plan to capture contact information from the user, let’s create a record variable to store that contact record data in the flow.
- In the Toolbox, click the Manager tab.
- Click New Resource.
- For Resource Type, select Variable.
- For API Name, enter contact.
- For Data Type, select Record.
- For Object, enter Contact.
- Click Done. In the toolbox, the Manager tab now contains a contact record variable resource.
- Click Save.
Add a Name Input Component to the Screen
You need to create form fields for the user to enter contact information on the screen. Let’s start with an input component that collects the contact’s name.
- On the canvas, double-click the Contact Info screen. The Edit Screen window opens.
- In the Screen Components pane, enter Name in the search box.
- Drag Name onto the screen canvas.
The properties pane now represents the Name input component.
- In the properties pane, for API Name, enter contactName.
- Scroll down and make sure Manually assign variables (advanced) is selected.
- Complete these steps to take what the user enters in the First Name and Last Name fields and store those values in the contact record variable.
- For First Name, select contact and then FirstName. The value is displayed as {!contact.FirstName}.
- For Last Name, enter {!contact.LastName}.
- For First Name, select contact and then FirstName. The value is displayed as {!contact.FirstName}.
- Click Done.
- Click Save.
Create a Record Choice Set for Accounts
You want the user to specify the parent account for the contact. Let’s create a record choice set for use later as a picklist on the screen.
- From the Manager tab in the toolbox, click New Resource and select Record Choice Set from Resource Type menu.
- In the New Resource window, enter these values.
Field Value API Name accounts Object Account Condition Requirements None—Get All Account Records Choice Label Name Data Type Text Choice Value Id - In the Store More Account Field Values section, complete these steps to take the user-selected account and store its ID in the contact record variable.
- For Field, select Id
- For Variable, enter {!contact.AccountId}.
- Click Done.
- Click Save.
Add a Picklist Input Component to the Screen
Now let’s add the picklist for the user to select the contact’s parent account.
- On the canvas, double-click the Contact Info screen.
- In the Screen Components pane, enter Picklist in the search box.
- Drag Picklist onto the screen canvas just below the Name component.
The properties pane now represents the Picklist input component. - In the properties pane, enter these values.
Field Value Label Account API Name Account Data Type Text - In the Select Choices section, for Choice, enter {!accounts}.
- Click Done.
- Click Save.
Add a Toggle Input Component to the Screen
Now let’s add the toggle for the user to specify whether (or not) to update an existing contact if one is found.
- On the canvas, double-click the Contact Info screen.
- From the Screen Components pane, drag Toggle onto the screen canvas just below the Account picklist component.
- In the properties pane, enter these values.
Field Value API Name update_toggle Label If this contact already exists, update the existing record. Active Label Update existing Inactive Label Create other contact Manually assign variables (advanced) unchecked - Click Done.
- Click Save.
Close and Open the Flow
- To exit Flow Builder, click the back arrow.
The flow list page appears. - To reopen the flow in Flow Builder, find New Contact on the flow list page, and click it.
Run the Flow to View the Screen
At this point, your flow can collect contact information from the user and store that information in flow variables. Let’s see what the screen looks like to users who run the flow.
- Above the canvas, click Run.
If you see an error message that says we can’t display a component because it isn't supported in Classic runtime, that means you're using an older Salesforce org. Not to worry! A quick settings change is all you need. From Setup, enter Process Automation Settings in the Quick Find box, then select Process Automation Settings. Select Enable Lightning runtime for flows, and click Save. Now reopen your flow, and click Run. - Play with the screen components and click Finish.
Because the flow has no elements to execute after the screen, nothing happens when the flow finishes. The flow simply runs again, which means that you see the screen again.
Congrats on building and even running a flow! So far, the flow only displays a screen that accepts user input. Next, you configure the flow to compare some of that user input with data in your org.