(This solution works in both Classic and Lightning Experience.)
This blog post was inspired by a use case from Stephanie Herrera where she needed to push an opportunity record’s multi-select picklist values to a custom object for data quality review.
Ok, ok, ok…I know, multi-select picklists are evil. This is the infamous image from MVP Steve Molis that he uses when he answers any question regarding multi-select picklists.
But, let’s assume, you had no choice and you had to implement a multi-select picklist field in your org.
The easiest implementation would be to use a formula field on the custom object that pulls in the multi-select values from the opportunity. However, there is no way to reference this field. You can try to write a formula that looks at the individual multi-select picklist values to populate the custom audit field, but depending on how many multi-select options you have, you may exceed the formula character count. So, that’s a no go too.
Rather than go the custom code route, we are able to do this declaratively using process builder and visual workflow.
You can take the multi-select values from one object and populate them as multi-select values in another object (which is what we will do in the post) or you can populate the multi-select values to a long text field if you only plan to view the options selected, such as if you wanted to capture the field history for a multi-select picklist. In this blog post, we will cover the first option – taking the values of one object and populating the multi-select picklist of another object.
Here are a few lessons learned from implementing this use case:
- Learn how to invoke flow from process builder.
- Create a flow sObject variable to easily reference values from a given record in your flow.
- 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.
Business Use Case: Addison Dogster is the system administrator at Universal Containers. Steven Moon is the Director of Operations. Steven needed a way to pull information from various objects so his team can see easily see where there may be data gaps. If a rep updates the multi-select picklist for an existing opportunity, he wants it to update the existing audit record, not create a new audit record.
Solution: Being the #AwesomeAdmin that Addison is, she was able to solution this declaratively using process builder and flow to populate a new custom object with this information.
To simplify the solution, in the post, we will only focus on passing the multi-select values from the opportunity object to this custom Audit object. We will assume you know how to create a tab for a custom object, add and configure related lists on a page layout.
Quick Steps:
- For the purposes of this blog, we are going to create a Picklist Value Set with the multi-select picklist items that we will use in the multi-select picklist on Opportunity and the Audit field. To create this, in Classic, you go to Setup | Create | Picklist Value Sets, or in Lightning Experience, you go to Setup | Objects and Fields | Picklist Value Sets.
We are creating the picklist value set so we only define the picklist values once and the custom multi-select picklist fields on the opportunity and audit objects will reference this picklist value set, no need to maintain the same picklist values twice.
Picklist Value Set should look like this*. We are calling this Multi-Select:
*The record will only display the fields where used once you reference the global value set on the Opportunity and Audit objects.
Best practice tip: Don’t forget to provide a description so you and other/future admins know what this global value set is used for.
The custom Opportunity object called Fruit Multi-Select should look like this, setting the global value set to the “Multi-Select” picklist value set:
Best practice tip: Don’t forget to provide a description so you and other/future admins know what this field is used for.
The multi-select picklist field in the Audit object is created in the next step.
2. Create the custom Audit object with three custom fields. To create this, in Classic, you go to Setup | Create | Objects, or in Lightning Experience, you go to Setup | Object Manager.
Set the Audit Object Name field to be an auto number.
The Account field should be a master-detail field to the Account object.
The Opportunity field is a lookup field to the Opportunity object.
The Fruit field is a multi-select picklist, using the Multi-Select global value set.
Best practice tips:
- Don’t forget to provide a description so you and other/future admins know what this field is used for.
- Assign field accessibility as needed.
Create a custom tab for the Audit Object. Add it to the relevant apps and for the appropriate profiles.
2. Navigate to the Account and Opportunity page layouts. Add the Audit Object related list to both page layouts. Configure the relevant fields to show on the related list.
3. Now, we need to create a flow that looks for the existing audit record to update and then takes the updated multi-select picklist values and updates the respective multi-select picklist on the Audit record, which we will invoke from process builder. The reason why we are building this in flow is that we cannot perform record lookups in a process. Go to Setup | Create | Workflows & Approvals | Flows in Salesforce Classic or Process Automation | Flows in Lightning Experience).
A. First, we are going to create a variable and an sObject variable.
The variable will store the audit record ID that is found in the record lookup.
This sobject variable will take all the values in the opportunity record for use in the flow. I decided to use the sobject variable rather than creating a variable to store the multi-select picklist since there is no multi-select picklist type to specify for a variable. Using the sobject variable, I’m going to map a field to the sobject variable field. I don’t need to specify the field type.
Best practice tip: Don’t forget to provide a description so you and other/future admins know what this variable is used for.
B. Create a Record Lookup flow element. We need to lookup the Audit custom object for a record where the account ID matches the opportunity’s account ID and the opportunity ID equals the opportunity ID passed from process builder. If one is found, take the audit record ID and store it in the variable varAuditRecordID.
Best practice tip: Don’t forget to provide a description so you and other/future admins know what this flow element does.
C. Now, as best practice, we want to perform a decision to ensure we found a record in the previous step. Let’s say for whatever reason, there was no record found, if the flow continues with the next step, record update, the flow will fault since there is no record to perform a record update on.
Here, we are just checking that the variable varAuditRecordID is not blank (i.e. “is null false”) before proceeding on with the flow.
Best practice tip: Don’t forget to provide a description so you and other/future admins know what this decision flow element does.
D. Next step, we will add a Record Update flow element. This will update a record in the Audit custom object where the ID equals the variable varAuditRecordID, specifically the Fruit Multi-Select picklist field with the values in the Fruit multi-select picklist field from sobject variable sObjectOpp.
Best practice tip: Don’t forget to provide a description so you and other/future admins know what this flow element does.
E. 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.
F. Set your flow starting point. And connect the flow elements and the fault connectors to match the below…
G. Save as and provide the following properties.
Best practice tip: Provide a description so you and other/future admins know what this flow element is used for.
H. Click the “Close” button.
I. On the flows screen, activate the flow.
4. Create the new process by going to Create | Workflows & Approvals | Process Builder in Salesforce Classic or Process Automation | Process Builder in Lightning Experience.
A. Provide a process name “Take Action on New/Existing Opps”, API name (auto-populated via tab key), description and select the process starts when “A record changes.”
Best practice tip: Don’t forget to provide a description so you and other/future admins know what this process is for.
B. Specify the first criteria “New Opp” where the condition will use the formula “ISNew().” We have to use the formula because you cannot use the point and click to specify a new record.
For the immediate action, we are going to create a new record on the Audit Object where we specify the following:
- Account reference [Opportunity].AccountId
- Opportunity reference [Opportunity].Id
- Fruit reference reference [Opportunity].Fruit_MultiSelect__c
C. Let’s now specify the criteria for updates to the Fruit Multi-Select field on an existing opportunity. Let’s call this “Multi-Select Updated” where the condition is Fruit_MultiSelect__c is changed boolean true.
For the immediate action, we are going to invoke the flow created in the previous step. for the variable sObjectOpp, we will select the record that initiated the process.
D. Activate the process.
Now, before you deploy the changes to Production, don’t forget to test your configuration changes.
- Log in as the intended user.
- Create a new opportunity from the Account and select items for the multi-select picklist field and save.
- Verify that a new audit record was created and all fields populated, esp. the multi-select picklist.
- Update the multi-select picklist on the opportunity and save.
- Verify that the existing audit record was updated to reflect the opportunity’s multi-select picklist.
Deployment Notes/Tips:
- The process builder, visual workflow, custom object/fields, page layouts, (if using Lightning Experience), Lightning record pages can be deployed to Production in a change set (or can be deployed using a tool such as Dreamfactory’s Snapshot).
- You will find the process builder and flow in a change set under the Flow Definition component type.
- Add the FLS permissions to the various profiles, as needed.
- Activate the process builder and flow post deployment as they deploy inactive in Production.