14

Are State and Country Picklist supported in Visualforce?

I'm trying to access them on Visualforce for Contact object but only a Textbox is displayed instead of a Dropdown.

My code is:

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

I've enabled Country and State Picklist in my org, and it shows perfectly fine in Standard Contact Edit form: enter image description here

  • Thnx for the Editing @Ralph. Next time I'll keep in mind these corrections. – VarunC Nov 5 '13 at 12:54
  • Happy to help @varun. Picture was very helpful, an excellent inclusion. – Ralph Callaway Nov 5 '13 at 17:48
14

Sry Found the solution to the question just after entering the Question.

The correct Field that should be referenced in Visualforce page is "MailingCountryCode" instead of "MailingCountry"

<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>

This code should work fine.

  • Same thing for MailingStateCode instead of MailingState – Scott Pelak Mar 2 '17 at 16:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.