Dependent picklist in Salesforce flow using Custom Metadata type – Video

Salesforce flow is great alternative for Visualforce pages used by admin. I have written, multiple blog post on Salesforce flow already and in this post we will discuss how we can create dependent picklist in Flow.

If you are already using flow, might know that creating dependent picklist is not supported yet. However we will be taking help of Custom Metadata types to create same behaviour in Salesforce flow.

Why Custom Metadata Type ?

In Summer 15, Salesforce has introduced Custom metadata types on platform. We can use Custom metadata types in place of List Custom settings because of one important benefit “deployment”. Custom Setting and Custom label has always been best friend of developers and admin for a long time to make Salesforce applications more configurable and dynamic. When I say “deployment”, whenever we deploy custom setting between sandboxes and production or distribute packages, records inside custom settings are not moved. We need to take help of API’s or Dataloader to load initial data in Custom setting after deployment. However with Custom metadata type , records are also moved. Setting up Custom metadata type is fairly simple and almost equivalent to List custom setting.

In this blog, we will create dependent picklist of three level. “Country” will be selected and on basis of it, “State” would be displayed and on basis of “state”, “city” would be displayed. Dependent picklists is displayed on same page in standard user interface however in Flow, it would not be possible. For each dependent picklist, we need to have one screen and therefore in our example, we will have total three screens.

First we need to setup Custom Metadata type which will have information needed to create dependency between fields. Navigate to “Setup | Build | Develop | Custom Metadata Types | New Custom Metadata Type”. For this example, we will name custom metadata type as “Dependent Picklist” with following custom fields:

  1. Object Name for Dependent Picklist (Created on which object)
  2. Controlling field API Name (API name of controlling field)
  3. Controlling field Value (Value which will control values in dependent field)
  4. Dependent field API Name (API name of dependent field)
  5. Dependent field value (Value which should be displayed on basis of value on controlling field)

Below image shows structure of Custom Metadata type created for this example

Custom Metadata Type used for dependent picklist
Custom Metadata Type used for dependent picklist

Once above structure is created, click on “Manage Dependent Picklists” to create record. Below image shows sample record created in this example

Sample records in Custom Metadata Type used for dependent picklist
Sample records in Custom Metadata Type used for dependent picklist

In above image, if we see first record “Trail__c” represents API name of Object on which we are going to create dependent picklist. “Country__c” is API name of field which will control values in dependent picklist. “State__c” is API name of dependent field. “Texas” is value, which would appear when “USA” is selected.

Now, lets start creating Flow by navigating to “Setup | Build | Create | Workflow & Approvals | Flows | New Flow”.

Drag “Screen” component from left to flow canvas. As, this is going to be first controlling field, so we don’t need any extra step here. Simply add “Dropdown List” on screen and in choice settings, choose “Create New | Picklist choice”.

Picklist choice - Salesforce flow
Picklist choice – Salesforce flow

Above setting will populate dropdown field with all options of field “Country__c” from object “Trail__c”.

Lets create two variables first. “varState” to store selected state in dropdown field and “varCity” to store selected city. We don’t need any variable for country because its type is not “Dynamic Record Choice”.

Its time to create a second screen for dependent picklist. This screen will show State of Country selected in previous screen. Drag a dropdown list field on screen two and in choice settings, choose “Create New | Dynamic Record Choice”.

Dynamic Record choice in Flow - State dropdown
Dynamic Record choice in Flow – State dropdown

Above screen is self explanatory and very simple. Now, we will move to create last screen which will display “city” on basis of “state” selected in previous screen. Drag a dropdown list field on third screen and in choice settings, choose “Create New | Dynamic Record Choice”.

Dynamic Record choice in Flow - City dropdown
Dynamic Record choice in Flow – City dropdown

Final flow will look like

Salesforce flow to create Dependent picklist
Salesforce flow to create Dependent picklist

and output will look like

Salesforce flow - Dependent picklist output
Salesforce flow – Dependent picklist output

Hope this will help, would appreciate your feedback on this post.

Posted

in

by


Related Posts

Comments

18 responses to “Dependent picklist in Salesforce flow using Custom Metadata type – Video”

  1. Thane Tagg Avatar
    Thane Tagg

    Great Post! Excellent way to get around the dependant picklists. Question though, for the Custom Metadata type everytime a new picklist is added will you need to update this dependancy?

    Also, it still feels strange salesforce hasn’t supported the standard picklist dependency into flows yet.

    Cheers,
    Thane

    1. Jitendra Zaa Avatar

      Thats right, Salesforce recently started supported even picklist. If we add any dependency then we need to keep Metadata Type updated.

  2. Gautam Majumdar Avatar
    Gautam Majumdar

    Hi Jitendra, I have situation where the dependency is with multiple levels. Say I have level 1, 2 and 3 picklists. Level 2 is dependent on level 1 ( this was easy) The next was, level 3 is dependent on level 2 and level 1. Does this solution help me set that up?

    1. Jitendra Zaa Avatar

      Yes this solution should help. However you will need new screen for each dependency.

      1. Leandro Avatar
        Leandro

        Hey Jitendra, for the multi-level dependency I had to create two separate Custom Metadata objects for each level, to avoid duplication of drop down values. Did you have another idea in mind for this?

  3. Max Pyne Avatar
    Max Pyne

    Hi Jitendra…Thanks for sharing this post!
    You really saved me a lot of coding effort as I have upto 6 level of field dependency for my work…

    I have a some queries although..Will be really helpful if you provide your inputs

    1.Since different screens need to be used for different picklists…I was thinking to add user selected values to be displayed in subsequent screens as a read only textbox.
    Ex: There are screen 1-6. Screen 2 should display screen1 selection as readonly on top of picklist in screen2 and so on!!

    I am able to display them in text boxes but they are not read only.Can you help me out with that?
    I can always use validation rules but its not a good user experience!!

    2.In some cases , controlling field values are appearing more than once i.e. not unique and dependant field values change based on multiple level dependency and are appearing more than once in screen

    For Ex:

    Segment System Role
    Brand IPC Developer
    Corp IPC Developer
    Corp IPC Admin

    In this case , if you select Segment – Corp, you will find two same values for System – IPC and IPC again!!
    Is there a way to restrict it?

    2.Thirdly . I have 200+ records with multiple dependencies.
    Instead of manually creating records in Custom Metadata Type object , is there a way to mass load data in mdt?

    1. Jitendra Zaa Avatar

      Here my suggestions :
      1. Use a variable to store value selected in previous screen and simply display variable on screen. It would be readonly.

      2. You can restrict it by making sure that Custom Metadata does not has duplicate entry in it. Otherwise you will need to use Javascript and beauty of click over code would be lost 🙂

      3. There is Custom metadata Dataloader, use it from here – https://github.com/haripriyamurthy/CustomMetadataLoader

  4. Bailey Rudd Avatar
    Bailey Rudd

    Thanks for the post! I’m trying to set up my flow based on your tutorial and for Screen 2 none of my values are populating. I set up my Custom Metadata Type and it’s controlling and dependant values, and used that as my dynamic record choice shown in the 2nd screenshot. What am I doing wrong?

    1. Jitendra Zaa Avatar

      In Second screenshot, second condition, instead of dependent_FIeld_value, try to compare controlling value with technology_Screen1

      1. Bailey Rudd Avatar
        Bailey Rudd

        Thanks! My flow works seamlessly now!

  5. Aviv Caspi Avatar
    Aviv Caspi

    Hi Jitendra,
    Thanks for sharing this useful knowledge.

    I followed the instructions and everything works good except for the fact that when I try to login to one of my users and use the button I get error of insufficient privileges.
    I was wondering if this is because I need to give any permissions to the custom metadata type object to all of my users. Do you know if this is needed?
    Thanks much,
    Aviv.

    1. Aviv Caspi Avatar
      Aviv Caspi

      I found the problem.. Flow User field on the user level has to be checked.

  6. Aviv Caspi Avatar
    Aviv Caspi

    Does anyone here know if the permissions user has are honored by the visual workflow?
    Thanks,
    Aviv.

  7. Abhishek Dhar Avatar
    Abhishek Dhar

    Hi Jitendra,

    Thanks for the video, it was very helpful. I have a problem while working on my dependent pick list MDT. I have 2 Controlling fields “Administration” and “Change My Access/User Records” and the dependent pick list values assigned accordingly in custom metadata.

    I followed the steps and created the dynamic record choice. The problem is, the picklist is only showing dependent values for “Administration” and it is showing “None” if I select “Change My Access/User Records” . Am I doing something wrong or is there a catch which I am unable to follow.

    Thanks for your suggestions.

    Abhishek Dhar

  8. Chintan Avatar
    Chintan

    @Jitendra, I followed your steps, I am unable to see the Custom Metadata Type under “Dynamic Record Choice” > “Create a choice for each”.
    What am I missing? Can you help?

  9. v Avatar
    v

    need code for custom metadata obj for picklist values

  10. Priya Singh Avatar
    Priya Singh

    Hi Jitendra,
    I need to create the same dependent picklist on a single screen . How can that be achieved using custom metadata?
    Could you please help here?

  11. Chris Chitemerere Avatar
    Chris Chitemerere

    Many thanks for this article. Is this still implementable in the current versions of Salesforce and i do not see any “Dynamic Record Choice Set” Component. I am looking for a solution to have two dependent picklists in two separate screens in screenflow.

    Kindly assist.
    Regards,
    Chris

Leave a Reply to LeandroCancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from Jitendra Zaa

Subscribe now to keep reading and get access to the full archive.

Continue Reading