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
SFDC VolunteerSFDC Volunteer 

State and Country Code picklists not available in Visualforce page

I recently enabled State and Country Code picklists for my org and wanted to access the STATE and COUNTRY code picklists on a visualforce page. However, when I try to reference them on a VF page, I receive the following error upon saving the VF page.
"Save error: Object type not accessible. Please check permissions and make sure the object is not in development mode"

I am using the following syntax to access these fields:
<apex:inputField id="ipFCountry" value="{!Contact.MailingCountryCode}" required="true" style="width:70%"/>
<apex:inputField id="ipFState" value="{!Contact.MailingStateCode}" required="true" style="width:70%"/>
Vinit_KumarVinit_Kumar
Can you post the whole code??

Tt seems related to permission,the below code works for me in my org :-

<apex:page standardController="Contact">
<apex:form >
    <apex:pageBlock mode="edit">
        <apex:pageBlockSection >
            <apex:inputField value="{!contact.MailingCountryCode}" />
        </apex:pageBlockSection>
    </apex:pageBlock>
</apex:form>
</apex:page>


Arunkumar RArunkumar R
Hi ,

Please check the profile level and field level security for the contact object for the user that you are running visualforce page.

If no object level permission means you may get this type of error.
SFDC VolunteerSFDC Volunteer

Here's the entire VF page.

<apex:page showheader="false" standardController="Contact" extensions="RegisterToDBController">
    <apex:image id="logo" value="{!$Resource.BAYVP_IS_Banner}" width="75%" height="50%"/> 
   <apex:sectionHeader title="" subtitle="Register with BAYVP"/>
      <apex:form id="frmRegisterToDB" >
           <apex:pageBlock id="theBlock" title="Register your name in our database">
           We will keep you posted on the upcoming events (via emails and regular mail) and other programs/activities.<p/>
           <b><font color="red">NOTE: </font></b>To update your existing information,  use the same email address that you used for your registration and the new information.
              <apex:pageblockButtons ><apex:commandButton value="Click to Register" action="{!saveContact}" /></apex:pageblockButtons>
              <apex:pageMessages />
              <apex:pageBlockSection title="Contact Info" id="pbs1" columns="2">
                   <apex:inputField id="ipFFirstName" value="{!Contact.FirstName}" required="true" style="width:70%"/>
                   <apex:inputField id="ipFLastName" value="{!Contact.LastName}" required="true" style="width:70%"/>                        
                   <apex:inputField id="ipFSpouseFullName" value="{!Contact.Spouse_Full_Name__c}" style="width:70%"/>
                   <apex:inputField id="ipFEmail" value="{!Contact.Email}" required="true" style="width:70%"/>
                   <apex:inputField id="ipFHomePhone" value="{!Contact.HomePhone}"  style="width:70%"/>
                   <apex:inputField id="ipFCellPhone" value="{!Contact.MobilePhone}" required="true" style="width:70%"/>
                   <apex:inputField id="ipFStreetAddress" value="{!Contact.MailingStreet}" required="true" style="width:70%"/>
                   <apex:inputField id="ipFCity" value="{!Contact.MailingCity}" required="true" style="width:70%"/>
                   <apex:inputField id="ipFState" value="{!Contact.MailingState}" required="true" style="width:70%"/>
                   <apex:inputField id="ipFZip" value="{!Contact.MailingPostalCode}" required="true" style="width:70%"/>
                   <apex:inputField id="ipFCountry" value="{!Contact.MailingCountryCode}" required="true" style="width:70%"/>
               </apex:pageBlockSection>
            </apex:pageBlock> 
    </apex:form>
</apex:page>
SFDC VolunteerSFDC Volunteer
Note that in my above VF page, I am only having MailingCountryCode as an example. I intend to include MailingStatecode too.
Vinit_KumarVinit_Kumar
The code seems fine ,I would suggest to go through the FLS at profile level for Contact object for the user who is facing this isssue.
SFDC VolunteerSFDC Volunteer
@Arunkumar:

I am using Force.com Sites for this Visualforce page. I have double-checked the PROFILE for the GUEST profile being used by that Force.com site and confirmed that the profile has READ and CREATE permissions to the Contact object. It also has READ and EDIT access to the MailingAddress field on the Contact object (where I would expect the State and Country code to be part of)
SFDC VolunteerSFDC Volunteer
The problem is occuring right when I try to save the VF page while being logged in as an Administrator. I have double-checked that both the System Administrator profile and the Guest user profile used by the Force.com Site where this VF page is being accessed from have READ and CREATE permissions to the Contact object (and specifically to the MailingAddress field).
Vinit_KumarVinit_Kumar
Can you check the debug logs as what is happening there ??
Arunkumar RArunkumar R
Here is the solution for your problem.. Your problem seems you have not enabled the State and Country Picklists in your organization.. This cause error while saving visualforce page.

To Resolve this error do the following steps and enable State and Country Picklists options..

Go to Setup --> Data Management --> State and Country Picklists


But make sure it will change your organization data,

In order to enable this option you must to do the following three options to enable.

1. Configure states and countries. --> You need to configure which country you want.

2. Scan now. --> This will scan all your existing data in contact.

3. Convert your data. --> Then convert all your existing data.

Once you finish those steps you will able to enable this feature.. 
SFDC VolunteerSFDC Volunteer
@Vinit: As I mentioned earlier, the error happens when I "SAVE" my Visualforce page after adding that new inputfield tag in ECLIPSE, NOT when I browse that page in the UI. As such, there is nothing I can obtain from the debug logs.

@Arun: I already did all that before I added the inputfield. Here's the message for STATE and Country picklist enablement in my org: "State and country picklists have already been enabled."
SFDC VolunteerSFDC Volunteer
I realize that this might be a "BUG".

If I access these new fields on a brand new Visualforce page, I do not get any error. However, if I reference them on an existing Visualforce page (existing before State and Country PIcklist was enabled for my org), I get the error.

I can access them just fine in APEX classes. It is just the "existing" Visualforce pages that cannot access the new MailingCountryCode and MailingStateCode fields. So, this does seem to be a BUG.

It is unfortunate though because unless enough people confirm and report this issue, I am not sure if SFDC will be willing to fix it. I opened a case with them but because my nonprofit does not have PREMIER relationship, they are unwilling to consider this (citing this as a DEVELOPER request instead of a FEATURE ACTIVATION related bug).

Can somebody reproduce this problem to confirm if the fields are NOT accessible on "existing" VF pages (pages existing before the State and Country picklists were enabled for your org) but available on brand new VF pages?
Marty C.Marty C.
Hello, SFDC Volunteer,

Based on what you're saying with the fact that newpages work fine, but old pages do not, would you check the API versions of your old and new pages? If you're using the Force.com IDE, you should be able to edit the page's "meta.xml" file to change the version. Alternatively you can change the API version in the native Developer Console or the Setup menu, both shown below.

Visualforce component API version setting in the Developer Console

Visualforce component API version setting in the Setup menu

From what I can tell, your Visualforce page needs to be configured to use API version 27.0 or higher in order for it to recognize the new StateCode and CountryCode fields.
CSIPBCSIPB
Hi Marty,

We updated our VF page to API version 27.0 and the MailingState and MailingCountry are still displayed as text fields. Is there any specifics that need to be added to the page in order for them to appear as Picklist values?

Thanks
Marty C.Marty C.
Hello, James, have you tried changing your field reference from MailingState to MailingStateCode? That made a difference for me when I used apex:inputField to present the field to users.
Scott ReisdorfScott Reisdorf
You can use the Schema Describe to get the Country Codes from the Contact metadata.
Below is a simple static helper function I use.

 public static List<SelectOption> getCountrySelectList(){       
          List<SelectOption> countryOptions = new List<SelectOption>();
        for(PicklistEntry value: Schema.Contact.Country_of_Citizenship__c.getDescribe().getPicklistValues()) {
           countryOptions.add(new SelectOption(value.getValue(), value.getLabel()));
        }   
        return countryOptions;
    }
doravmondoravmon
Has this problem been solved?
SFDC VolunteerSFDC Volunteer
No. I had to recreate the visualforce pages with the same exact code to overcome this permissions issue. It is weird and I realized that it might have something to do with the ORG setting on SFDC side of things. In my case, it is a non-profit org, which is an enterprise edition version, but I have historically seen tons of such issues in the non-profit org while not seeing any at my workplace (which uses an unlimited and PAID edition of SFDC).