How To

Build a Search Tool Using Flow

Search1Search

This blog post was inspired by a flow question asked by fellow MVP Toya Gatewood. This one’s for you, Toya!

Here are a few lessons learned from implementing this use case:

  • Create an interactive flow with dynamic record choice and loops.
  • Learn how to invoke a flow and pass parameters into a flow from a custom button.
  • Provide descriptions, where provided, in Salesforce. This may be tedious step, I know, but your future self will thank you when you are trying to remember what you configured or assist other/future admins when troubleshooting or enhancing what was built. This includes variables, the purpose of a flow, what each flow element does, etc.

This blog post is meant to get your creative juices going on how you can customize a search for records and update a record with the search selection using flow in your own Salesforce org.

Business Use Case:  Addison Dogster is the system administrator at Universal Containers. Steven Moon is the Director of Sales. The Sales Reps have complained about the standard Agreement lookup used to associate an agreement to an opportunity. While the Agreement lookup was filtered to to show the agreement associated to the Account, Sales Reps also want to confirm the agreement by viewing the agreement’s associated existing opportunities. This requirement cannot be handled via the out of the box filtering.

Before we go forward, this is the data model. Agreement is a custom object with a lookup to an Account. An Account can have one to many Opportunities and one to many Agreements. An Opportunity can be associated to an Agreement and an Account.

DataModel.GIF

Solution: Being the #AwesomeAdmin that Addison is, she was able to solution this by building a search function declaratively using flow screens.

This is the implementation in Lightning Experience:

AddanAgreementToAnOpp-LEX.gif

Open the image in full screen

This is the implementation in Classic:

AddanAgreementToAnOpp-Classic.gif

Open the image in full screen

Quick Steps: 

Pre-requisites:

  • The Account is a required field on the Opportunity page layout.
  • Data model structure shown above is already built in the org.
  • This custom field was created in the Agreement object that uses a formula to pull agreement information to be used in the search results.

AgreementFormulaCustomField.GIF

1. Let’s create a visual workflow to handle the lookup of the agreements associated to the account,

Flow-AddAnAgreementToAnOpp

For those using Salesforce Classic, visual workflows can be found in Create | Workflows & Approvals | Flows. In Lightning Experience, it is found under Process Automation | Flows.

A. First, we will create all the resoucess we need to reference in our flow. This is done by going to the Resource tab in the Flow Designer and creating a new resource.

Best practice tips: Don’t forget to provide a description so you and other/future admins know what the resource is/is used for.

This first resource is a Constant  that will store a line break used in the search results showing the associated opportunities.

lineBreakConstant.GIF

We will create the text template resource to hold the opportunities associated to the agreement.

tt_SearchResults.GIF

Now, we have to create the following variable resources.

varAccountId.GIF

varAgreementFormula.GIF

varAgreementID.GIF

varOppID.GIF

varOpportuityName.GIF

varOpportuityStageName.GIF

varOpportunityID.GIF

varSearchResultsRow.GIF

Now, let’s create two SObject Collection Variable resources.

sObjCollectionofAgreements.GIF

sObjectCollectionOpportunities.GIF

Lastly, we are going to create an SObject Variable resouce.

sObjLoopRecord.GIF

B. Create Fast Lookup flow element to query the agreement object to find the agreement(s) that associated to the account on the opportunity. Any records found will be stored in the sObject Collection Variable sObjCollectionofAgreements. We need to fields on the agreement record for use later in the flow.

Best practice tips: Don’t forget to provide a description so you and other/future admins know what this fast lookup is used for.

Flow-AddAnAgreementToAnOpp-FastLookup.GIF

C. Create the a Decision flow element to determine whether there are any agreements found in Step B. Essentially, we need to look at the sObject Collection Variable sObjCollectionofAgreements and see if there are values (or is null = false). The default outcome will be set to No Agreements Found.

Best practice tips: Don’t forget to provide a description so you and other/future admins know what this decision does.

Flow-AddAnAgreementToAnOpp-Decision.GIF

D. In our next step, we add a Screen flow element where we inform the user that there are no agreements associated with the account. The screen element shown is a display text.

Best practice tips: Don’t forget to provide a description so you and other/future admins know what this screen does.

Flow-AddAnAgreementToAnOpp.GIF-NoAgreementFoundScreen.GIF

E. We are going to create a Screen flow element that will show the agreement(s) associated with the account on the opportunity. Set the navigation option to “Don’t show Previous button” and uncheck Show Pause button.

We are going to add a display text and a radio button that will have a dynamic choice.

Flow-AddAnAgreementToAnOpp-DynamicRecordChoice.GIF

Follow the steps in the animated gif to build the screen.

Best practice tips: Don’t forget to provide a description so you and other/future admins know what screen is for.

Flow-AddAnAgreementToAnOpp-DynamicChoice.gif

Open the image in full screen

F. We now need the Fast Lookup flow element to look up open opportunities associated with the selected agreement. We will lookup the opportunity object with where the agreement matches the selected agreement ID and the opportunity stage is not Closed Won or Closed Lost. It will store the records found in the sObject Collection Variable sObjectCollectionOpportunities, where it will store the opportunity name and stage.

Flow-AddAnAgreementToAnOpp-FastLookupOpps.GIF

G. We will create a Decision flow element to determine whether there are any opportunities found in Step F. Essentially, we need to look at the sObject Collection Variable sObjectCollectionOpportunities and see if there are values (or is null = false). The default outcome will be set to No Opps.

Best practice tips: Don’t forget to provide a description so you and other/future admins know what this decision does.

Flow-AddAnAgreementToAnOpp-DecisionOpps.GIF

H. Create a Record Update flow element to update the agreement field on the opportunity. It will find the record in the Opportunity object where the Id equals the variable varOppID and update the agreement field with the variable varAgreementID.

Flow-AddAnAgreementToAnOpp.GIF-RecordUpdate.GIF

I. Let’s create a Screen flow element that will show a confirmation screen noting tat the agreement has been added to the opportunity. Set the navigation option to “Don’t show Previous button” and uncheck Show Pause button.

We are going to add a display text.

Flow-AddAnAgreementToAnOpp-ScreenConfirm.GIF

Follow the steps in the animated gif to build the screen.

Best practice tips: Don’t forget to provide a description so you and other/future admins know what screen is for.

Flow-AddAnAgreementToAnOpp-ScreenConfirmation.gif

J. Now, let’s create a loop flow element that goes through the sObject Collection Variable sObjectCollectionOpportunities and assigns the current value to the loop variable (sObject variable) sObjLoopRecord.

Flow-AddAnAgreementToAnOpp-Loop.GIF

K. Create a Record Lookup flow element to lookup the Opportunity object for the loop record and store the Id, Name and StageName fields in the variables varOpportunityID, varOpportunityName, varOpportunityStageName, respectively. This information will be used in the display of the opportunity search results.

Flow-AddAnAgreementToAnOpp-RecordLookup.gif

L. Create an Assignment flow element and take the variable varSearchResultsRow and add the text template tt_SearchResults.

To refresh your memory, this will add the following for each opportunity in the collection:

{!varOpportunityName} | {!varOpportunityStageName}{!lineBreak}

Flow-AddAnAgreementToAnOpp-Assignment.GIF

M. Let’s create a Screen flow element that will show a confirmation screen listing the opportunities associated with the selected agreement. Set the navigation option to “Don’t show Previous button” and uncheck Show Pause button.

We are going to add three display text elements.

Flow-AddAnAgreementToAnOpp-ScreenConfirmOpps.GIF

Follow the steps in the animated gif to build the screen.

Best practice tips: Don’t forget to provide a description so you and other/future admins know what screen is for.

Flow-AddAnAgreementToAnOpp-ScreenConfirmationOpps.gif

Open the image in full screen

N. Add the subflow Send Flow Fault Email. For instructions on how to create this, go to Step 2 of blog post: Maximize Maintainability With Process Builder and Componentized Visual Workflow.

O. Set your flow starting point. And connect the flow elements and the fault connectors to match the below…

Flow-AddAnAgreementToAnOpp-Connectors.GIF

P. Save as and provide the following properties.

Best practice tip: Provide a description so you and other/future admins know what this flow is used for.

Flow-AddAnAgreementToAnOpp-FlowProperties.GIF

Q. Click the “Close” button.

R. On the flows screen, activate the flow.

Flow-AddAnAgreementToAnOpp-Activate.GIF

2. Now, we need to create the custom Opportunity button that invokes the flow and passes the parameters.

Take note of the flow URL.

Flow-AddAnAgreementToAnOpp-FlowURL.GIF

Navigate to the Buttons, Links, and Actions section for the Opportunity object.

We will call the button “Add an Agreement” that is a Detail Page Button.

Use this for the URL:

/flow/Add_an_Agreement_to_an_Opportunity?varOppID={!Opportunity.Id}&varAccountID={!Opportunity.AccountId}

Let’s deconstruct the URL.

  • “/flow/Add_an_Agreement_to_an_Opportunity” is the URL from the flow detail record.
  • “?” is needed when we want to pass parameters into the flow.
  • “varOppID={!Opportunity.Id}” indicates that we are passing the opportunity record’s ID as the flow variable varOppID.
  • “&varAccountID={!Opportunity.AccountId}” indicates that we are passing the opportunity record’s account ID as the flow variable varAccountID.

Best practice tip: Provide a description so you and other/future admins know what this custom button is used for.

AddanAgreementtoAnOppCustomButton.GIF

3. Add the custom button to the opportunity page layout.

OpportunityPageLayout.GIF

Congrats, you configured the solution! You’ve implemented a process to allow the user to search for an agreement to add to the opportunity.

Now, before you deploy the changes to Production, don’t forget to test your configuration changes.

Deployment Notes/Tips:

  • Visual workflow, custom button and opportunity page layout(s) can be deployed to Production in a change set (or can be deployed using a tool such as Dreamfactory’s Snapshot).
  • Activate the visual workflow as it is deployed as inactive into Production. 

13 thoughts on “Build a Search Tool Using Flow

  1. Nice! I have not used a constant to store a line break before, that was pretty cool. And I like the idea of creating a custom formula field to hold values used in the search. That is great. I too often try to do everything in the flow itself – sometimes it makes more sense to create datapoints outside of the flow and bring them in.

    I have tried to create a more traditional search before in Flow, searching against thousands of Products, and showing a limited set of results. It kind of worked but was kind of hacky. Search is definitely not a core functionality of Flow but I like your method. Thanks for sharing!

    Like

  2. Hi! Are you letting the user decide which agreements to add to the opportunity via the screen or are you adding all of found agreements? My use case is such that I need to show the user all records found and then let the user a. select one by one or b. click on select all and all records found will be added to the new object. I’ve been able to create the flow without any screens but will only work if I add all records found. Now I’m working on the screen element but a little stuck.

    Like

  3. I think you may be able to use a multi-select picklist to allow for multiple selections. My use case was just to select one. I’m not sure whether you can do a select all. I’ve never had a need for that.

    Like

  4. Maybe a stupid question, but i hardly can read the animated gifs, is there a way to make them bigger (opening in a new window didnt work out for me)

    Like

  5. Hi jenwlee
    I want to ask what is the purpose and function of Formula text in Agreement named “Account Name”
    And what is formula for this

    Like

  6. This custom field that was created in the Agreement object that uses a formula to pull agreement information to be used in the search results.

    Like

Comments are closed.