Salesforce Visual Workflow – Advanced Flows


‘For the second part of the Salesforce Visual Workflow tutorial, I’ve asked Keith Sadler, Consultant (and Flow guru) from Appirio to return and expand on some really cool functionality and advanced features. We are going to build off of the original Flow that was designed for creating a Case from a Lead record that was accidentally generated via Web to Lead.  If you were able to make it through the entire tutorial from the first VWF blog, congratulations!  Now, we are going to learn a few more advanced tricks, again to help you think a little out of the box.  Note: Any changes made to your original Flow will be saved in a new version, so that you can always revert back if needed.’ – Mike

Here is the scenario:

We have implemented the previous Flow, and the business team was excited for the great solution and quick turn around time, but now they have some enhancement requests.  They like the fact that the lead fields are being mapped over to the new case record into the “Web Name” and “Web Email” fields, but the users still must manually edit the case and add a contact through the standard look-up. To make things more painful, they must search by the name provided, and not by email.  The good news is that we can automate this in the Flow we have built.  Our actual requirements are as follows:

  1. Automatically attach the Case to an existing Contact if there is a contact in the system with the same email address as the Lead

  2. Give user the ability to choose the contact it should be associated with if there is more than one existing contact with the same email address.  (I know you may be thinking that this is because there are duplicates, but in our scenario, this is the actual business process to create duplicate contacts if they work for multiple accounts in the system.)

  3. If there are no contacts in the system with the same email, keep the original functionality.

Part One: Set Up Flow and Save New Version

Let’s first open up our original Flow, and get this set up for customization to meet the requirements above.

  • Open the original Flow? Setup | Create | Workflow and Approvals | Flow | Click “Open” next to your Flow.

  • Since we will be adding logic to the Flow before the case is created, the first thing that you should do is delete the arrow connecting the first two elements.  To do this, just click on the arrow (it will turn green), then push delete on your keyboard.

  • Next, go ahead and highlight the bottom two elements, and drag them down the palette to give yourself room in order to insert additional elements.

  • Once you have done this, click “Save As” on the top left control bar of your flow.  Do NOT rename your flow, and make sure this is set to “Save as new version”.

  • Your Flow should look like the one below.

Salesforce Visual Workflow : Step 1 - Delete Arrow between 2 elements


Part Two: Check for Existing Contact and Build Decision

Alright, now that we have our Flow set up and ready to go, let’s look at our first two requirements.  We need to check to see if there are any contacts in the system based on the Lead email.  We also would like to give the ability for the end user to select which contact should be associated to the case, if there is more than one.  We will accomplish this by using a few different elements such as Data Lookups, Decisions, and Dynamic Choices.  Let’s get started!

  • The first thing we want to do is check to see if there is at least one contact in the system with a matching email

    • Drag the Record Lookup element into the Canvas under the Lead Lookup

    • Name this “Contact Lookup”

    • In “Filters and Assignments” section please set the following:

      • Set the Lookup dropdown to “Contact” as this is the record we are looking for.

      • In the filters below, we would like to set two filters

        • Email equals LeadEmail

        • Email does not equal GlobalConstant.EmptyString

          • GlobalConstant.EmptyString is how you  say “Null” in Visual Workflow

      • At the bottom where it says “Assign record’s fields to variables”, click the trash icon on the right-hand side to remove the row.  If you do not do this, you will get an error when saving.  The point to this is that we are not selecting any specific contact yet, so we do not need to assign any variables.  All we are doing is checking to see if there is at least one in the system.

    • Click Save

    • Connect the Lead Lookup element with new Contact Lookup Element

    • Save your Flow!

Salesforce Visual Workflow : Step 2 - Contact Lookup

Salesforce Visual Workflow : Step 3 - Delete Variable assignment

  • Now that we have the lookup created, this element will actually produce a True or False result.  If there is a contact found in the system where Email = LeadEmail, the value “True” will be returned, if not, “False” will be returned.  With that being said, we need to use a Decision element that determines what will happen next.  If the result is True, the user should pick the contact to be associated.  If the result is false, then we just move on to the Create Case Element.

    • Drag the Decision element out onto the Canvas under the Contact Lookup.

    • Name this “Contact Exists?”

    • For Decision elements, Outcomes must be defined. In our case, we only have two outcomes based on the “True” or “False” from the Contact Lookup element.

    • Create the first outcome by putting “Found Contact” into the name field

      • Below this we need to add a filter that determines when this outcome will be met.

      • This should be set to Contact Lookup equals GlobalConstant.True

      • So if we think about this logically, we are saying that if the Contact Lookup returns the value of “True”, we want the outcome to be “Found Contact”.

    • Next we must create a Default Outcome.  This is the outcome that will occur if the other defined Outcomes’ criteria are not met.

      • Click on the Default Outcome link on the left side, and add the name “No Contact”

      • Remember anytime there is not a contact found, this Outcome will occur, because the “Found Contact” will happen anytime the Contact Lookup finds a contact record with a matching email.

      • Click Save and breathe 🙂

        Salesforce Visual Workflow : Step 4 - Contact Exists

      • Now that the decision is built, go ahead and drag an arrow from the Contact Lookup element down to the “Contact Exists” element.

      • Next drag an arrow down from the “Contact Exists” element and attach it to the Create Case element.

        • Notice that we now have to pick an Outcome.  Choose “No Contact”

        • Save your Flow!

Salesforce Visual Workflow : Step 5 - No Contact Canvas



Part Three – Creating a Dynamic Choice to Pick an Existing Contact

Creating dynamic choices can be one of the most powerful functions of Visual Workflow.  A dynamic choice allows you search for records, then display the returned data to the end user in a picklist, or radio buttons to select.  Once that is record is selected, you can then take the ID, as well as any other information from that record and store into different variables to use within your Flow.

 One thing to note is that when you display records to the end user in a picklist, or radio buttons, you must pick a single field from the record that will be used as the values to choose from.  Because of this, we are going to start this part off by creating a new custom field on the contact record, to give end user a better experience for selecting the contact.  We would like the value they have to choose from look like {Contact.Name} – {Account Name}.  Let’s get started!

  • Create a new custom Formula field on the contact record

  • Name this “Flow Name” and set to Text

  • Copy and paste this text to Formula:  FirstName&” “&LastName&” – “& Account.Name

  • Remove from page layouts and Save

OK, now we have the field that we will use for our Dynamic Choice.  Let’s go back to our flow and finish building this out!

  • Drag a Screen element from your Palette to the Canvas to the right-hand side of the “Contact Exists” Decision.

    • Name the Screen “Contact Selection Screen”

    • Click the Add a field tab

    • Drag the “Display Text” field from the left side, over to the right.  What we want to do with this is tell the end user that a contact has been found with the same email address.

    • Click on the Display Text field that you dragged to the right

    • Give this a unique name of “ContactFoundDescription”

    • Now you can put text below that will be displayed to the end user.  Go ahead and add ”Please choose a contact below that has been found with the email address “{!LeadEmail}”.

      • Keep in mind that {!LeadEmail} is my variable.  Make sure to select yours from the resource dropdown above the text box

    • Now click the add field tab and drag the Radio Button field over to the right-hand side, under the Display Text

    • Name this “Select Contact”

    • Leave all values default, but check the Required checkbox field

    • We now need to add the dynamic choice for the radio buttons

      • Click on the Choice drop down, and select Create New | Dynamic Choice

      • Name this “ChooseContactChoice”

      • Select “Contact” from the object dropdown, because we are wanting to query contact records

      • Set filters to Email equals LeadEmail (This will return all contacts with the email address)

      • Set the Choice Label to “Flow Name” (Choice label it the value that is displayed to end user to choose)

      • Set the Choice Stored Value to ID (This is so that we store the contact ID when someone chooses the contact.  This will be reused when associating the case to a contact)

      • Set the Sort Results by to Flow Name and Ascending

      • Note that you can store additional fields from the record to Variables if you would like to use these in the Flow

      • Click OK
      • Click OK

Salesforce Visual Workflow : Step 6 - Choose Contact Choice

  • Now connect your decision to the Screen element, and then the Screen element to your Create Case Element.  It should Look like this:

Salesforce Visual Workflow : Step 7 - Flow Image

  • Edit the Create Case Element that is already on the Canvas

    • Add a new field to map

    • Set this to ContactID mapped to SelectContact (This is the dynamic choice field that stores the contact ID

    • Click OK then Save your Flow

  • In order to prevent the Flow from entering a loop, we will want to add one additional screen to the end of the flow.

    • Drag a screen element to the very bottom of the Flow and name this Close Window

    • Click add a field, and drag Display Text to the right.

    • Name this CloseWindowDescription

    • Add text “Flow is complete, you can now close out of Window”

    • On General Info tab, set to “Do not show Finish Button”

    • Click OK

    • Now edit and make sure the Display Case element is set to “Do not show Previous Button”

  • Make sure all elements are connected then Save your flow!

Now that the Flow is complete you can click close.  Remember, Now you will need to Activate your new version.  Go ahead and try it out!

Choosing the Right Automation Tool

Right now is a great time to be a Salesforce Admin. With Lightning Process Builder, Workflow Rules, Visual Workflow, and Approval Processes, we have many great automation tools in our utility belt. As a Productivity Protector we are often working to streamline business process and deliver real business value. And if you watch any superhero […]


Salesforce CSI: Uncovering What was Previously Built

So, you’ve inherited an undocumented org…now what? You’ve started a new job. (Congrats!) You’re volunteering for a non-profit. (Go you!) You’re a consultant who’s just started working with a new client. (It begins!) You ask your new boss/supervisor/manager for the documentation of the Salesforce org and you get a blank stare and a shrug. Oh […]


9 Things Your Consultant Won’t Say To Your Face

I recently read a very interesting article about the behind-the-scenes truths in sales and it inspired me think about the truths of consulting. Having worked on a few consulting projects, I reached out to the Cloud for Good team who has worked on hundreds of implementation projects and here is what they came up with: 1. We […]