function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Simran SuriSimran Suri 

Auto populate custom picklist based on value from another custom picklist on Standard Contact Page (Create/Edit)

Hi,
I have two custom picklist fields on Contact object - Country and Country Code. Both fields have 250 picklist values each. I want to auto-populate the country code as soon as the value of country is filled by the user while creating/editing a Contact. Can anyone please guide me? I am quite new to salesforce development.
Thanks for your help !
Best Answer chosen by Simran Suri
Shun KosakaShun Kosaka
You can use dependent picklists. Choose Country as controlling field and Country code as dependent field.
You also need to set Country Code as required on Contact page layout to remove default picklist value '--None--'

See also:
https://help.salesforce.com/HTViewHelpDoc?id=fields_defining_field_dependencies.htm&language=en
https://help.salesforce.com/apex/HTViewSolution?id=000221030&language=en_US

All Answers

Shun KosakaShun Kosaka
You can use dependent picklists. Choose Country as controlling field and Country code as dependent field.
You also need to set Country Code as required on Contact page layout to remove default picklist value '--None--'

See also:
https://help.salesforce.com/HTViewHelpDoc?id=fields_defining_field_dependencies.htm&language=en
https://help.salesforce.com/apex/HTViewSolution?id=000221030&language=en_US
This was selected as the best answer
Naveen DhanarajNaveen Dhanaraj
Yes this Can be done by using Dependent Picklist values,If you choose a country and country code will be dependent to country field.
Naveen DhanarajNaveen Dhanaraj
Based on country ,choose country code
Simran SuriSimran Suri
Hi @Shun & @Naveen,
Yes, For now, I have done it in this way in my sandbox, but, I am unable to default the dependent picklist value.
PS: I cannot make the fields Country & Country Code as 'Required'. Is there any other alternative, so that I can default the country code values as soon as the country is selected without making these fields as mandatory?
Shun KosakaShun Kosaka
I think you don't have to set Country as required. In this case, Country Code will be '--None--' when Country is '--None--'.

Using a formula field for Country Code could be another way.
For examle,
Case(Country__c,
"India", "IN",
"Japan","JP",
"United Status", "US",
"default value")
However, formula field is read-only and cannot be showed in the edit mode.
Simran SuriSimran Suri
Hi @Shun,
Yes, you are right for the first case. I don't have to make the Country field as required. But, I can make the Country code mandatory on the page layout in order to default it. It worked! Thanks a lot !
However, formula field will not suit my requirement since it cannot hold large amount of picklist values and cannot be shown in Edit Mode.