Dynamic picklists could become the most powerful feature of your Salesforce forms. A simple web-to-lead form created in Salesforce uses basic HTML picklists, which are not very useful.

What makes a picklist dynamic?

A dynamic picklist includes options retrieved live from another source, offering a user-friendly interface to select the correct option(s). For example, a dynamic picklist on your Salesforce form might enable you to choose from a list of contacts within your Salesforce account.

Dynamic picklists have many other features like:

  • Options are searchable
    It is not feasible to expect the user to scroll through all the options of a dynamic picklist to find the correct one. Picklists should have the option to search options.
  • There is no limit on the maximum number of options
    What if your picklist can potentially have 10,000 possible options. It is not feasible to load all options in advance. A good dynamic picklist would allow users to select any of these 10,000 options while not loading all of them in advance.
  • Options have support for descriptions and photos
    Your options can be accompanied by descriptions or photos.
  • Options can be grouped
  • Support for multiple selections
  • Picklist options can be dependent on other fields
    This is a very powerful feature, and often overlooked. Example your dynamic picklist allows users to select from a list of contacts for a particular country. However the user can also select the country here in another field. A dynamic picklist can have a set of options that depend on the value of another field.

Here is what a dynamic picklist would look like on your Salesforce form

Creating dynamic picklists in Salesforce

This is where FormCrafts comes in. FormCrafts is a form builder for Salesforce. It has a lot of features, including dynamic picklists. Let us learn how to create dynamic picklists in FormCrafts.

Basic setup

Create a new form on your FormCrafts dashboard, if you haven't already.

Click on Salesforce at the top-left of the form edit screen. Then, connect your Salesforce organization by clicking on Connect an organization.

Next click on Add Field (top-right) and click on Dropdown. Note that dynamic picklists only work with dropdown-type fields. When editing the dropdown field look for Dynamic Source, next to Option List.

Salesforce dynamic picklist basic setup
Salesforce dynamic picklist basic setup

When you click on (select source) you would be able to see a list of Salesforce objects you can pull data from. Search for Contact. You will now see 5 other columns:

Salesforce dynamic contact picklist
Salesforce dynamic contact picklist

We will explore various configurations below, but here is a primer:

  1. Id field
    This is the value of your option. In most cases we want the value to be the unique Id of your record. For Contact that would be Contact ID. For Account that would be Account ID.
  2. Label field
    This is the main option text displayed to the user. For Contact it makes sense to use Full Name.
  3. Description field
    This is the optional description text for the option. We will leave this blank for now.
  4. Image field
    This is the optional image field for the form. We will leave this blank for now.
  5. Group by field
    This is the optional group creation parameter. This would usually be something with recurring values like Department or Country.

For this example select Contact ID under Id field, and Full Name under Label field. Now click on Preview (top-right) and try it out.

Adding description

Adding description to your picklist options is straightforward. Select a field under Description field. For example: to display a contact's country, choose Mailing Country as the description.

Here is how our picklist looks now:

Adding photos

You can even add photos to your options. For this to work your Salesforce object must have a URL field that links to an image. Let us select Photo URL under Image field.

Here is our picklist now:

Some examples where you'd want to add photos to a dynamic Salesforce picklist:

  1. A logo selection picklist
  2. A contact selection picklist
  3. A travel destination selector

Grouping options

You can group your picklist options using the Group by field. Here we would select a recurring field in our Contact record. Example, this could be department, country, industry type, etc ... For this example select Mailing Country.

Here is our picklist now:

Some examples where you'd want to add groups to your Salesforce dynamic picklist:

  1. A contact picklist
  2. A city picklist
  3. A product selection picklist

Using SOQL

Basic usage

Let's go back to the step where we selected the Contact object from the list under Dynamic Source. Click on the field again and select Salesforce SOQL. This now allows us to use SOQL queries to fetch records, giving us a lot of flexibility. For this example we will try to fetch Contact records, and their associated id, name and email fields. The SOQL query is:

select id, name, email from Contact

Under Id field, type in id. Under Label field type in name, and under Description field type in email. Our configuration looks like this:

Salesforce SOQL-generated dynamic picklist configuration
Salesforce SOQL-generated dynamic picklist configuration

Relationship queries

You can use relationship queries to find related records and put that information in the picklist. Example, we want to fetch a list of contacts. Our option label should be the contact's full name. We want our option description to be the name of the associated account. The SOQL query here would be:

SELECT id, name, Account.Name FROM Contact

And under Description field we would type in: Account.Name

Dependent picklists

The options of your picklist can depend on the values selected in other fields. Example we have a main picklist that fetches a list of Accounts. We also have a picklist that shows only Contacts linked to the chosen Account.

Let us add another dropdown field to our form and configure this field to pull all Accounts. Our configuration would look like this:

Salesforce dynamic dependent picklist - Account
Salesforce dynamic dependent picklist - Account

Note the field Id for this field. It should be in the format fieldXX.

Now configure the Contact picklist field to use Salesforce SOQL (under Dynamic Source). We will use this query to fetch results:

SELECT id, name, Account.name FROM Contact WHERE Account.Id = '[field17]'

Here you would replace field17 with the field Id of the Account field from above. The Contact picklist fetches the id, name, and Account name of Contacts that have matching Account Id with the field above.

Here is our configuration for the Contact picklist:

Salesforce dynamic dependent picklist - Contact
Salesforce dynamic dependent picklist - Contact

Here is this setup in action:

Using templates

What if we want the option description to have a particular format, like Works at XXX instead of simply the Account name?

That is also possible. In the above example, under Description field, type in:

Works at [Account.Name]

Our configuration now looks like this:

Salesforce dynamic picklist with option templates
Salesforce dynamic picklist with option templates

Dynamic picklist builder

FormCrafts offers a dynamic Salesforce picklist builder that can help you preview your picklist options, and also debug common issues. To access the picklist builder look for the button Picklist builder under Dynamic Source while editing your field.

Salesforce dynamic picklist builder
Salesforce dynamic picklist builder