You need to sign in to do that
Don't have an account?
SFDC 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%"/>
"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%"/>
Tt seems related to permission,the below code works for me in my org :-
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.
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)
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..
@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."
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?
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.
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.
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
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;
}