Loading

Access the state and country picklist through Apex

게시 일자: Oct 13, 2022
상세 설명
This article gives you sample code to access the state and country pick-list values:
솔루션
Makes sure the state and country picklist is enabled in the ORG.
  • For Lightning UI : "Setup | Data | State and Country/Territory Picklists | Complete all the steps" 
  • For Classic: "Setup | Data Management | State and Country/Territory Picklists | Complete all the steps "
  • Find below the link that has steps to enable the state and country pick list in the ORG. 
 
1. Following is the sample code for accessing all the country codes in the ORG
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());
}

2. Following is the sample code for accessing all the state codes in the ORG
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());
}
 
Please note that this is just the sample code and will not fulfill the entire business requirement
Knowledge 기사 번호

000387645

 
로드 중
Salesforce Help | Article