Visual Flows are a powerful tool for any administrator on the Salesforce platform. With a drag and drop interface and a suite of possible actions, Visual Flows can let you level up in system automation without having to write a single line of code (and if you’re comfortable with a bit of Visualforce, you can take them even further). With the powers of Visual Flows and the new features that Salesforce rolled out in Winter ’15, there’s plenty of reasons to implement Visual Flows as part of your business processes. In this blog post, I’ll explore another way to extend your Visual Flows by using Custom Settings.
For all the benefits of flows, there are some annoying drawbacks. I won’t get into all of them here, but one nuisance is that once you’ve activated a Visual Flow, making any change to it requires saving it as a new version, and then activating that version. Now, ultimately this built-in change control requirement is a good thing—it’ll prevent you from breaking something that’s active and working—but when you just need to update a picklist value, it can be a nuisance to have to create a new version of the Flow and activate it. Custom settings to the rescue! Read on to learn how to use Custom Settings with Dynamic Choices within the flow to give yourself more flexibility with your Visual Flows.
First, you need to identify a picklist that you want to be able to easily update values on in your Visual Flow. For instance, maybe you want a bit more flexibility with a field for listing a Referral Source for new Contacts. Once you’ve decided what picklist you want to customize with Custom Settings, it’s time to create your Custom Settings record.
Navigate to Setup > Develop > Custom Settings and click “New”. You’ll now see a screen where you can enter the Label and Name for your Custom Setting. We’ll name this one “Referral Source.” Make the Setting Type “List,” and set the Visibility to “Public.” Click “Save.” You’ve now created a Custom Setting.
Next, you need to add a field to your custom setting—this will be used to store the picklist values you are pulling into your Visual Flow. Click “New” on your Custom Setting page, and you’ll see a menu similar to when you are creating a custom field on an object anywhere else in Salesforce. In this case, we’ll just select the Checkbox option and click “Next.” Name the field “Active.” This checkbox will be used to determine which values will get pulled into your picklist. Click “Next,” then “Save,” and you’ve created your Custom Field on your custom setting. You’re now ready to start adding values that you want to appear within your Visual Flow.
To begin adding values, click the “Manage” button on the Custom Setting. Next, Click “New.”
You’ll see a screen with two fields: “Name” and “Active”. Populate the “Name” field with one possible picklist value and check the “Active” box. Click “Save and New” and repeat for as many values as you would like to add. NOTE: Remember, if the picklist in your flow will be mapped to a picklist field (not a text field), make sure that each value you save in the custom settings directly matches a possible value of that picklist field.
Once you’ve created your custom setting values, it’s time to add the dynamic picklist to your Visual Flow. Open your Flow, and open the screen element where you would like the picklist to appear. Click the “Add a Field” tab, and double click either “Radio Button” or “Drop Down List”.
Click the field, and label it “Referral Source”. Then, in the “Choice Settings” section at the bottom left of the window, click the dropdown arrow and select Create New > Dynamic Choice. A new window will appear where you can name your Dynamic Choice, and select the source for the Dynamic Choice values. Where it says “Create a choice for each”, start typing “Referral” into the box, and your custom setting, “Referral Source” should appear in the drop down list. Select that value, and more fields will appear in the window to determine which values to use.
Set the criteria on the Dynamic Choice to “Active” equals “True.” This will mean the Dynamic Picklist will pull in any values you have marked as “Active,” and will omit values that are not Active. Set the Choice Label and Choice Stored Value to “Name,” and click “Okay.”
If it gives you an error when you click “Okay,” try scrolling down to the “Additional Options” section and clicking the trash can next to the blank variable mapping.
You’ve now created your dynamic picklist, and you just need to map it to a field for when the record is created. Open your Record Create element, and map the “Referral Source” screen choice field to wherever you would like it to save when the record is created. Click “OK”.
Now, it’s time to test. Click “Run” in the upper left corner of the Flow editor. When you get to the screen where you added your Dynamic Choice, you should see values that reflect all of the values that you added to your Referral Source custom setting.
If you go back to your custom setting and uncheck “Active” on some values, they will be removed from the picklist—all without you needing to actually edit the Visual Flow itself! Likewise, if you add new Active values to your custom setting, those values will automatically appear in your Dynamic Picklist (remember, if you add values in the custom setting, also add those values to the picklist field that the Dynamic Picklist is mapped to, or you’ll hit errors when the Visual Flow tries to create records with the new picklist values).
Once you’re comfortable using Custom Settings to create Dynamic Choices within your Visual Flow, you can take it even further. If you include additional fields on your Custom Setting record, you can pull those in as default values in your Flow, allowing you to set dynamic default values based on a single picklist selection. This can allow you to have a more streamlined and flexible flow, instead of having to add additional Decision elements and Assignment elements. For instance, consider that with different Referral Sources, you also wanted to assign different Contact Record Types, Default Owners, and Solicitation preferences. You can add these additional fields to your Custom Setting, and assign those values to variables within your Visual Flow, keeping things simple for your users to use and for you to maintain.
The first step is to go back to your Referral Source custom setting and add three additional fields: Contact Record Type (Text, 18), Owner ID (Text, 18), and Do Not Solicit (Checkbox). Click “Manage” and you will see the records for the custom setting values you have already created. Edit each of those custom setting values to populate the new fields with the defaults that you want your Visual Flow to use when that picklist value is selected.
After you’ve updated your custom setting values to populate the new fields, it’s time to add some additional mapping into your Visual Flow. First, you’ll need to create variables that can receive the values from your Custom Setting. From the Resources palette, click “Variable”, and create a variable named “var_ContactRecordTypeId” with a data type of Text, then click “OK.” Repeat this to create a variable for each additional field that you added to your Custom Setting.
Open the Screen Element where you placed the Referral Source dynamic choice, and click the “Referral Source”field. Under “Choice Settings” in the lower left, double-click the pencil icon that appears next to your Dynamic Choice. A window will appear with the details that you set up for the Dynamic Choice earlier in this tutorial. Now, scroll down to the “Additional Options,” and click the link that says “Add Row”. In the Field column, select one of your new fields from your Custom Setting, and in the Variable column, select the corresponding Variable that you just created. Continuing adding rows and mapping fields to variables until you have mapped all of the fields that you added to your Custom Setting, then click “Ok.”
Now, the default Record Type, Owner, and Solicitation preference from your Custom Setting will be selected based on whatever value a user selects on the Referral Source picklist. The final step is to map your variables in your Record Create element. Open your Record Create element, and add rows to map your Variables to fields on the Contact record.
Once you’ve added and mapped each of your new variables, click “Ok.” Save your Visual Flow, and click “Run” to test that your new default values are appearing for records created in the Flow. If you ever need to incorporate another set of possible defaults into your Visual Flow, it’s as simple as just adding a new set of values to your Custom Setting, instead of having to make any changes to the Visual Flow itself!
Custom Settings allow you to be more flexible with your Flows and incorporate new values in lists without ever having to actually edit the Flow itself. I’ve given one example of how this approach could be leveraged within an organization, but there are many other possibilities. How can custom settings and dynamic picklists in Visual Flows help your non-profit?