+ Start a Discussion

Help with Multi-Picklist field on Visualforce

Dear all,
Below is my visualforce page. City is a dependent field which works with Country. Everytime I change the stage and save the page, city field gets reset when I advance to next stage. For some reason, City field is not retaining values on next stage. For example, if I select country as USA in "Prospecting" stage and save the page with "New York" as city. In next stage which is "Needs Analysis", City field automatically resets to blank. Can someone please help with a controller or a visualforce workaround?

<apex:page standardController="Opportunity" sidebar="false">
  <apex:sectionHeader title="Edit Opportunity" 
  <apex:form >
    <apex:pageBlock title="Edit Opportunity" id="thePageBlock" 
      <apex:pageMessages />
      <apex:pageBlockButtons >
        <apex:commandButton value="Save" action="{!save}"/>
        <apex:commandButton value="Cancel" action="{!cancel}"/>
      <apex:actionRegion >
        <apex:pageBlockSection title="Basic Information" 
          <apex:inputField value="{!opportunity.name}"/>
          <apex:pageBlockSectionItem >
            <apex:outputLabel value="Stage"/>
            <apex:outputPanel >
              <apex:inputField value="{!opportunity.stageName}">
                <apex:actionSupport event="onchange" 
              <apex:actionStatus startText="applying value..." 
          <apex:inputField value="{!opportunity.amount}"/>
          <apex:inputField value="{!opportunity.closedate}"/>
      <apex:pageBlockSection title="Closed Lost Information" 
            rendered="{!opportunity.stageName == 'Prospecting'}">
        <apex:inputField value="{!opportunity.Country__c}"  
        <apex:inputField value="{!opportunity.City__c}"/>
      <apex:pageBlockSection title="Closed Lost Information" 
            rendered="{!opportunity.stageName == 'Needs Analysis'}">
        <apex:inputField value="{!opportunity.Country__c}"  
        <apex:inputField value="{!opportunity.City__c}"/>

Amit Chaudhary 8Amit Chaudhary 8
Hi Chetan Jomiwale,

I tested your code it looks good to me. When stage is "Prospecting". Then you are selecting Country and Stage. Make sure after selecting Country and Stage you need to click on save button. Then after changing  the stage to "Needs Analysis" Country and Stage will not visiable as Blank.

Pic 1:-

User-added image

PIc 2:-
User-added image

NOTE :- Make sure after selecting Country and Stage you need to click on save button. Country and Stage value should be saved at record level.

Please mark this as solution by selecting it as best answer if this solves your problem, So that if anyone has this issue this post can help
Hi Amit, for me everytime I open the saved opportunity and change stage value, city field gets reset. For example,

In screenshot 1 - I have opened a saved Opportunity. You can see Opportunity has saved values "Dallas" and "New York"

User-added image

In screenshot 2 - Now if I change the stage to "Needs Analysis", page says applying values... and City field resets to default/blank. 

User-added image

Can you please help?
Mohit Bansal6Mohit Bansal6
Hi Chetan Jomiwale

Can you check, if there is any dependent relation between Stage and City fields? 
Thiyagarajan Selvaraj (SFDC Developer)Thiyagarajan Selvaraj (SFDC Developer)
Hi Chetan Jomiwale,

Remove the action region from your code, it should work. But, when you change the stage value and the country value is blank, salesforce will throw an error. To avoid that, remove the required attribute from the country apex:inputfield and create a validation rule on opportunity object (like ISPICKVAL(Country__c,'')). 

It is because, when an AJAX request is generated, Force.com server process only the components within actionregion. 
Thank you Thiyagarajan, I tried as you suggested but it doesnt work. I removed actionRegion from my code but still everytime I change Stage, City dependent picklist gets reset to default. Country works fine and values dont change, but City values are reset everytime I change stage.