Get the list of countries and states as described here
country code - country name
Schema.DescribeFieldResult fieldResult =
User.Countrycode.getDescribe();
List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
System.debug('Picklist::'+ple);
for( Schema.PicklistEntry f : ple){
System.debug(f.getLabel() +'::'+ f.getValue());
}
state code - state name
Schema.DescribeFieldResult fieldResult = User.statecode.getDescribe();
List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
System.debug('Picklist::'+ple);
for( Schema.PicklistEntry f : ple){
System.debug(f.getLabel() +'::'+ f.getValue());
}
The problem is that we don't know which state belongs to which country. That is not as easy to solve, but some solutions are available here
TL;DR, check out Integration Values. https://help.salesforce.com/articleView?id=admin_state_country_picklists_integ_values.htm&type=5
If I enable the picklist, what all will get affected?
When you enable state and country picklists, all the UI that shows standard address fields will show picklists for state and country.
In the APIs (Soap, SOQL, Apex, and the like), you'll gain access to StateCode
and CountryCode
fields. These are the fields backing the new picklists in the UI.
The text-based State
and Country
fields that you have now will still be API-accessible. If they're being reported on, they'll show up in the report re-labelled "State (text only)" and "Country (text only)".
When you update a StateCode
or CountryCode
field, the corresponding State
or Country
text field will be updated to the Integration Value associated with that state/country, so that any existing integrations that work with States and Countries won't break. The inverse is true also: if you change a State
or Country
text field value, as long as the new value is a valid Integration Value for some state/country, the StateCode
or CountryCode
field will be updated to match.
(If you update a State
or Country
text field to a value that isn't a valid Integration Value, the update fails with an error, because it's essentially the same scenario as trying to set a restricted picklist to an invalid value.)
Do I need to change all the apex class, vf pages, web services?
If you don't, the Apex, VF, and web services will keep referencing the text fields. Maybe that would work for your org, or maybe not. It would be safest to test it out in a sandbox before turning it on in production.
Any integrations or custom UIs that don't use a constant State/Country name will need to be updated, otherwise they'll get errors when they try to set the fields to unexpected values.
On enabling this picklist, does only picklist is shown only on UI and data type remains to text field or the field type gets changed to picklist?
Neither. The picklist fields are added to the UI. The text fields are removed from the UI, but they are still available in API contexts.
There is talend webservice, do i need to change it?
Possibly (caveat I have no idea what talend does). It depends on whether talend works with full country names or just country codes, and whether it uses them consistently. If it consistently uses country codes, you'll definitely want to update that integration to use the CountryCode
fields.
Best Answer
In the end we resolved this by updating the data corresponding to the country mapped