I use the following code in order to retrieve the list of configured states in the org.

private static List<String> getStateList()
    List<String> stateList = new List<String>();
    Schema.DescribeFieldResult fieldResult = User.statecode.getDescribe();
    List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();        
    for( Schema.PicklistEntry f : ple){
    return stateList;

However, when trying to deploy the code, I run into the following error: Variable does not exist: User.statecode

Can anyone shed some light on this issue - I am unable to deploy without this error being fixed.

  • 4
    Is State Country Picklist enabled? Jun 17, 2021 at 15:19
  • 1
    Welcome to Salesforce Stack Exchange. Thank you for including the actual error. But please edit your question to also include where you are attempting to deploy the code (e.g., scratch org, sandbox, Production). It could make a difference to the specifics of an answer.
    – Moonpie
    Jun 17, 2021 at 15:24

3 Answers 3


StateCode field is available for org if country picklist is enabled in the org.

Make sure, that you have it enabled for your environment.

in lightning:

Setup -> Data -> State and Country/Territory Picklists -> Complete all the steps

  • Thanks for the quick reply! I had thought that I already turned it on in the target org but this has solved my issue :) Jun 18, 2021 at 7:59

If you're trying to build an Unlocked Package, you need to specify this feature in your Scratch Org Definition File.

Example definition file:

{ "edition": "Enterprise", 
  "features": ["StateAndCountryPicklist"]
  • Thank you! I wasn't but this is good to know for the future :) Jun 18, 2021 at 8:00

As per the documentation you need to first:

Makes sure the state and country picklist is enabled in the ORG

This is likely the problem.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .