The following screenshot summarizes this configuration:
Get Records screen configuration for contacts
Create another Get Records element for the Account object with the same configuration that’s shown in the preceding screenshot; the only things we need to change are the object type (which should be set to Account), the matching condition based on the Duns Number field (instead of the Contact.Email field) and the new FoundAccountID text variable, which we will use to store the matching Account ID (instead of the FoundContactID variable).
Now, based on the fact that the account has not been found, we can create or update a new record.
Connect the Customer Info Review screen to the Find Contact By Email element and the Find Contact by Email element to the Find Account by Duns Number element.
Let’s create a new Decision element that will decide on whether the account is created or updated:
Decision element on the Account not found condition
Here, we have two outcomes (we can have more, but in our scenario, we only have a two-way decision): that is, either the account has been found or it hasn’t, depending on the FoundAccountID variable value (the Account found outcome has no conditions as it is the else path of the Account not found outcome). Use the EmptyString global value whenever you need to check null/empty values.
Connect the Find Account by Duns Number element to the Account to be created? decision element.
Let’s create a Create Records element so that we can create the account and an Update Records element so that we can update the account (they are quite similar):
Create Records screen configuration for the account record
Connect the Account to be created? element to the Create Account element and select the Account not found outcome.
Before connecting the Update account element, we need to set the ID of our account record with the FoundAccountID value (we are going to be doing an upsert).
Then, we need to create a new Assignment element to set this value:
Setting the account’s ID
Now, connect the Account to be created? element to the Set Account Id assignment screen and select the Account found outcome. Then, connect it to the Update Account element.
At this stage, we have created/updated the account record. We need to do exactly the same for the contact record, but with a few modifications. For this, we need to do the following:
- Create a new Assignment element to set the contact’s account ID with an assignment set to {!contact.AccountId} Equals {!account.Id}. This has to be connected to the account’s Create/Update elements of the previous flow branch.
- Create a new Decision element (contact to be created?) based on the FoundContactID variable with two outcomes: Contact not found and Contact found. This new element will follow the previous Assignment element.
- Create a new Assignment element to put FoundContactID into our contact variable.
- Create a Create Records element to create a brand-new contact.
- Create an Update Records screen to update our contact with its old ID.
- Create a final screen to tell the user that customer acquisition has been completed.
- Create an error handling screen to tell the customer whether any of the database operations (the Get Records or Create/Update records elements) went wrong.
In order to show flow error messages, we need to use the $Flow.FaultMessage global variable, as shown in the following configuration for the Error Message screen:
Screen to show flow error messages
If you followed previous instructions correctly, this is what you will have:
Final flow example
Mission accomplished – easy, eh?
So far, we have created a few actions, but the flow has already become a bit messy. The secret is designing simple flows that can be linked with one another using the subflow element, which can call subflows.