Dynamic picklists are one of the most powerful features of FormCrafts. Salesforce picklists created in FormCrafts have many features, like:

  • Data is fetched in real-time
  • Options are searchable
  • There is no limit on the maximum number of options
  • Options have support for descriptions and photos
  • Options can be grouped
  • Support for multiple selections
  • Picklist options can be dependent on other fields

The simplest example of a dynamic picklist would be a dropdown that allows users to select a contact.

Basic setup

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

On the form edit screen click on Salesforce (top-left) and click on Connect an organization to link your Salesforce 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 fairly straightforward. Simply select a field under Description field. For this example we want to show a contact's country as the description so we would select Mailing Country.

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:

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:

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 also use relationship queries to lookup related records and then populate 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. Then we have another picklist that only shows a list of Contacts associated with the above selected 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. So the Contact picklist is using the SOQL query to fetch the id, name, and Account name of all Contacts where the Account Id matches the Account Id of 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

Picklist builder

FormCrafts offers a 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