Require Fields on Other Objects to be Filled Out in Order to Create a Record (Quote) – Learning Flow 1.C

No one likes dirty data, there are lots of tools out there to help dedupe leads, accounts, etc.  But what about if a field isn’t filled out.  Well, there are required fields, and validation rules, but what if that doesn’t work when creating a record since a User doesn’t know that information until later, but you would like to have that information required before creating a related record?  Enter Flows to the rescue!  That’s right, you read it correctly, require fields on other Objects in order to create a new related Object, all with point and click!  For this lesson, part 1.C of the Learning Flow series, you’ve been given a request from Management, before anyone can Quote a customer, it is required that a Billing Address is filled in on the Account and that there is a phone number listed so that Finance can reach the person/company and send an invoice.  For the Billing Address, the requirement is that every Billing Address has a street, city, country, zip, and if the country is US, USA, United States, or United States of America, there should be a State as well.  (State and Country pick lists have not been turned on in this example, but if you have them turned on in your Org, you can do this with them as well!)  It’s time to get started!

First, open the Flow, Quote Entry, that you created in part 1.A.  Select the Quote Entry Screen element, the Assign Quote Information Assignment element, and the fcQuote Fast Create element.  You can do this by holding ctrl and clicking on each element or by clicking your mouse and dragging your mouse so that all elements are inside the box the mouse lines create when you click and drag.  Just don’t include other elements in the box!  Once all three are highlighted, click on any of the highlighted elements and drag them down, enough to put another element between the flOpportunity Fast Lookup element and the Quote Entry Screen element.  It’s that easy to move multiple elements around in Flows!

Quote Entry Flow With Space For Account Lookup

In the Palette, drag and drop a new Fast Lookup element between the flOpportunity Fast Lookup and the Quote Entry Screen.  Enter the Name and Unique Name as flAccount and in the Look up field select Account.  For the Field you should use Id, Operator should be Equals, and in Value type opp.id.  You’ll see a list, select the AccountId from the sovOpportunity section of the sObject Variables.  The Value should populate with {!sovOpportunity.AccountId}.  Leave the Sort results by as unchecked since you’re searching for one Account by Id.  You should see this.

Quote Entry Flow Fast Lookup Account Part1

For the Variable, you’ll need to create a new sObject Variable.  Do this by clicking on the drop down arrow, select Create New, then sObject Variable.  For the Unique Name, enter sovAccount (for sObject Variable Account), enter in the Description “The related Account of the Quote”, set the Input/Output Type as Input and Output, and select the Object Type as Account.

Quote Entry Flow sovAccount

Click OK.  {!sovAccount} should be showing in the Variable field on the Fast Lookup for the Account (flAccount).  There should always be a related Account for every Quote, so there is no need to check the box to Assign null to the variable, but it can’t hurt either.  In the Fields area, you’ll need to select Phone, BillingStreet, BillingCity, BillingState, BillingPostalCode, Billing Country, and Id.  To add more fields beyond the first field that shows up, click the Add Row.  Your screen should look like the below image.

Quote Entry Flow Fast Lookup Account Part2

Click OK.  Make sure to always Save your Flow.  Since you might have activated your Flow at the end of the last lesson, as well as to keep your Flow versions the same as the lesson number, click Save As and enter the Name of the Flow as Quote Entry v3.  For Description, enter, “Added a Fast Lookup for Account.”.

Quote Entry Flow Save Screen v3

Click OK.  You’ll see a General Warning, “flAccount (Fast Lookup): ‘flAccount’ is not connected to anything.”  Don’t worry, you’ll connect everything at the end, click OK to make sure your work is saved!  Select the Quote Entry Screen, Assign Quote Information Assignment, and fcQuote Fast Create and drag them lower so that another element can fit between flAccount Fast Lookup and Quote Entry Screen.

Quote Entry Flow With Space flAccount Quote Entry

In the Palette, click on the Decision element in the Logic section and drag it to the canvas between the flAccount Fast Lookup and the Quote Entry Screen.  Name the Decision element, “Is Account Information filled out?” and then hit tab, Salesforce should update the Unique Name to Is_Account_Information_filled_out.  This brings you to the Outcomes section.  You should see on the left hand side in the dark box, EDITABLE OUTCOMES.  Click on the [New Outcome].  Enter the Name as, “No, Account Information is not filled out”, hit tab and have Salesforce fill out the Unique Name.  So far, this is what your screen should be showing.

Quote Entry Flow Decision Element Account Information

For Resource, select {!sovAccount.Phone}, for Operator select “is null”, and for Value, type True and select {!$GlobalConstant.True}.  You’ll repeat this for a few more lines by clicking Add Condition to add another condition.  For ease of building and reading, the next few lines will display R: (for Resource) & O: (for Operator) & V: (for Value).  You’ll see the screen shot at the end, so make sure your screen looks the same at the end.

R: {!sovAccount.BillingStreet} & O: is null & V: {!$GlobalConstant.True}

R: {!sovAccount.BillingCity} & O: is null & V: {!$GlobalConstant.True}

R: {!sovAccount.BillingState} & O: is null & V: {!$GlobalConstant.True}

R: {!sovAccount.BillingPostalCode} & O: is null & V: {!$GlobalConstant.True}

R: {!sovAccount.BillingCountry} & O: is null & V: {!$GlobalConstant.True}

R: {!sovAccount.BillingCountry} & O: equals & V: US

R: {!sovAccount.BillingCountry} & O: equals & V: USA

R: {!sovAccount.BillingCountry} & O: equals & V: United States

R: {!sovAccount.BillingCountry} & O: equals & V: United States of America

That is the last condition, now it’s time to click on the drop down menu next to Add Condition that says, “All conditions must be true (AND)” and select “Advanced logic (Combination of ANDs and ORs)”.  You’ll notice that instead of saying AND between each condition (Resource field) it now is numbered.  This allows you to be able to add advanced logic, which is precisely the need for the Billing Country if it is US, USA, United States, or United States of America.  Since the business goal is to require State only when the Country is one of those 4, then you’ll need to change your logic to adjust.  First, replace all “AND”s in the Logic box with ORs.  Now, since line 4 (BillingState) is only true if in combination with 7, 8, 9, or 10, remove the OR and 4 after the 3 so the Logic box reads, “1 OR 2 OR 3 OR 5 OR 6 OR 7 OR 8 OR 9 OR 10″ without a 4.  Now, after the 10, hit space and type ” AND 4″.  Your line should read, “1 OR 2 OR 3 OR 5 OR 6 OR 7 OR 8 OR 9 OR 10 AND 4”.  Now, since only 7, 8, 9, and 10 are dependent on 4, put two “(” right before 7, one “)” after the 10, and one “)” after the 4.  The Logic box should read, “1 OR 2 OR 3 OR 5 OR 6 OR ((7 OR 8 OR 9 OR 10) AND 4)”  What this says is that if Phone is Null or Street is Null or City is Null or PostalCode is Null or Country is Null or Country is Either US, USA, United States, or United States of America and the State is Null, then follow this decision, otherwise, go through the normal decision.

Quote Entry Flow Decision Account Element With Condition Logic

Now click on [Default Outcome] and for the Name, enter “Yes, Account Information is filled out.”

Quote Entry Flow Decision Account Information element Default Outcome

Click OK, then click Save to save your work!  If you see a general warning, don’t worry, you still need to connect your work.  If you see an error, go back and double check everything to make sure it is correct, the logic can sometimes be tricky!

Click in the canvas but in an area with no element or line so that nothing has green around it, the green is used as a selector indicator letting you know what item or items have been selected.

Quote Entry Flow No Green

Now, click the line/arrow that is coming out of the flOpportunity Fast Lookup element so that it and only it is green.

Quote Entry Flow Green flOpportunity Arrow

Hit delete or backspace on your keyboard.  The arrow is gone!  Now, click the diamond at the bottom of the flOpportunity Fast Lookup and drag your mouse over the flAccount Fast Lookup and let go.  From here on out, you’ll read “connect” and the element names to know that is what you are doing.  Connect flAccount Fast Lookup to the Is Account Information Decision element.  Connect the Is Account Information Decision element to the Quote Entry Screen.  Notice anything different?

Quote Entry Flow Decision Routing

This is the decision routing, you have to let the system know, based on the decisions in the Decision element, when should the system connect these two elements.  In this case, you want to select, Yes, Account Information is filled out. (The opposite of the picture, which is what defaulted originally)  Now click OK.  You’ll notice that between the Is Account Information Decision element and the Quote Entry Screen, you’ll actually see, “Yes, Account Information is filled out”, which is very helpful when you are trying to understand a Flow!

Quote Entry Flow With First Decision Element Connected

Make sure to Save your work!  (No general warnings this time!)

There are two options for the next part.  Option A, all fields are available to be filled in through a Flow.  This is the main example.  Option B, not all fields are able to be entered (at least not without programmatic development) into the Flow.  This might include State and Country pick lists, making sure a different action is done like Clean an Account with Data.com before proceeding, etc.  You’ll be able to review both options, but Option A will be the most User friendly, so if possible, go with Option A!  (If not possible for some parts but possible for others (like State and Country pick lists), you can create 2 decision elements, one with things that are possible to allow Users to enter the information and one with things that are not easily possible to stop users from moving forward, and do both Option A AND Option B as a result)

OPTION A: Allow Users to enter the required information into the flow and Update the record.

Go to the Palette and click the Screen element and drag it to the right of the Is Account Information Decision element.  Name the Screen, Clean Account Data.  Select Don’t show Finish button in the Navigation Options section and uncheck the Show Pause Button.

Quote Entry Flow Clean Account Data Screen Initial View

Now, click on Add a Field and drag over 6 Textbox fields.

Quote Entry Flow Clean Account Data Screen 6 New Textbox Fields

Click on the first Field and for the Label enter Phone.  Select the default value as {!sovAccount.Phone} and select required.  Textbox 2 should be labeled Street with the default value as {!sovAccount.BillingStreet} and required checked.  Textbox 3 should be labeled City with the default value as {!sovAccount.BillingCity} and required checked.  Textbox 4 should be labeled as State with the default value as {!sovAccount.BillingState}, leave required as unchecked.  Textbox 5 should be labeled as Zip/Postal Code with the default value as {!sovAccount.BillingPostalCode} and required checked.  Last but not least, Textbox 6 should be labeled Country with default value of {!sovAccount.BillingCountry} and required checked.

Quote Entry Flow Clean Account Screen With Inputs And Default Values

You’ll use the decision element again to see if the State has been filled out, so there is no need to create a validation rule since the decision element already holds the information.  Click OK, then connect the Is Account Information Decision element with the Clean Account Data Screen.  Save your Flow.

From the Palette, drag and drop an Assignment element to the right of the Clean Account Data Screen element.  Name this Update Account Information.  The Assignments should be as follows:

V: {!sovAccount.Phone} & O: Equals & Value: {!Phone}

V: {!sovAccount.BillingStreet} & O: Equals & Value: {!Street}

V: {!sovAccount.BillingCity} & O: Equals & Value: {!City}

V: {!sovAccount.BillingPostalCode} & O: Equals & Value: {!Zip_Postal_Code}

V: {!sovAccount.BillingCountry} & O: Equals & Value: {!Country}

V: {!sovAccount.BillingState} & O: Equals & Value: {!State}

Quote Entry Flow Account Update Assignment

Click OK.  Connect the Clean Account Data Screen element to the Update Account Assignment element.  Save your Flow.

Quote Entry Flow With Update Account Assignment

From the Palette, drag the Fast Update element to the position right above the Update Account Assignment element.  For the Name, enter fuAccount and select {!sovAccount} as the Variable.

Quote Entry Flow fuAccount

Click OK.  Connect the Update Account Assignment element with the fuAccount Fast Update element, then connect the fuAccount Fast Update element with the flAccount Fast Lookup element.  Save your Flow.  Your Flow should look like the below image.

Quote Entry Flow v3 OptionA Loop

This will send the Flow back to lookup the Account after the update and go through the Decision element again, making sure that if the Country is US and the State is not entered in, it will send the User back to the Clean Account Data Screen to add in the State.  To make sure this doesn’t get too confusing for the User, let’s enter in a help bubble for them as well as a note in the Flow that if the Country is United States, they need to enter in the State.

First, double click the Clean Account Data Screen, then click the State Textbox field.  In the Help Text section on the left, type in,

State is required when the Country is the United States.

Quote Entry Flow State Help Information

Next, click on Add a Field, and drag the Display Text output right below the State.  Click on Display Text.  For the Unique Name, enter

USNeedsState

and type in the main box,

State is required if the Country is the United States.

Quote Entry Flow Address Clean Screen With State Display Text

Then click OK and Save your Flow.

From here, it’s time to test!  Find an Opportunity that has an Account with bad data, preferably a US Account without a State!  Click run and make sure to enter the ?vOId={!Opportunity.Id} to test!  It worked!

OPTION B: Restrict Users from going any further in the Flow until the other information is filled out.

While always nice to be able to clean data in real time, there may be circumstances where you can’t.  For those, the Flow is much more simple than Option A.  In the Palette, click the Screen element and drag it to the left of the Is Account Information Decision element.  Type the Name and Unique Name as STOP.  Select, Don’t show Previous button, and uncheck the Show Pause button.

Quote Entry Flow Stop Screen Element Initial Setup

Click on Add a Field, select the Display Text output, and drag it below Stop.  Click on [Display Text] and enter the Name as Reason.  In the text box, type,

The Account must have all billing address information filled out, which includes Street, City, State (if Country is US), Zip/Postal Code, and Country, as well as the Phone number for the Account.  Please go to the Account, fill this information out, and try to build your quote again at that time.

Quote Entry Flow Stop Screen Reason Textbox

Click OK.  Click into the canvas but not on an element so that there is no green showing.  Click on the line from the Is Account Information Decision element to the Clean Account Data Screen element.  Once it is green, click delete/backspace to delete the connection.  Now connect the Is Account Information Decision element to the STOP Screen.  Save your Flow!  (Don’t worry about the general warnings for the 3 elements that are not connected to anything)

Quote Entry Flow With STOP Screen Connected

Test it out, make sure to use an Opportunity that has an Account with bad Data!  If done properly, you’ll see your screen telling you to go fix the bad information and try again.  Click Finish and your Flow is done.  Before moving on, go back to your flow, delete the connection between the STOP Screen element and the Is Account Information Decision element and connect the Is Account Information Decision element to the Clean Account Data screen element.  Save your Flow. (Don’t worry about the STOP Screen not being connected to anything)

Congrats!  You just learned how to prevent and help clean up dirty data on related objects using Flow!

 

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s