How to create dynamic drop downs in Salesforce?

H

I had task of creating two drop downs for a custom object in Salesforce:

1. Country – Listing all countries of the world.
2. State – Listing all States for selected Country dynamically.

This wasnt a visualforce page, had to do it through custom fields itself. So I came across Dependent Fields concept in Salesforce. Its pretty easy to use and I just loved the way Salesforce has made it so easy to assign for users to create as much big lists of depenciens as possible. Here are best practices that helped me:

1. Create a main field as picklist – Country
2. Add your options – All countries list
3. Create another picklist – State
4. Put all of the options here – So all the states for all the countries. Note, you should already have the list sorted as per country, so if there are only 2 countries US & Canada:

– First put Alabama to Wyoming all states in order.
– Then put Alberta to Saskatchewan after them.
*** Dont alphabetically order entire list of states together.

5. Now go back to Country field and under “Field Dependencies” click on New. Choose Dependent fields and save.

6. Now next is the page where you’ll admire smartness of Salesforce team, with a very user friendly GUI, you can simply select a range of options and click on assign values, thats it. Since we already sorted in order we want, one set of states per country appear below other and we dont waste time finding out which state relates to which country and under which column we should assign it.

Hope this post helps you.

About the author

Nishant Bamb
By Nishant Bamb

Category