You need to sign in to do that
Don't have an account?

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?
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" subtitle="{!opportunity.name}"/> <apex:form > <apex:pageBlock title="Edit Opportunity" id="thePageBlock" mode="edit"> <apex:pageMessages /> <apex:pageBlockButtons > <apex:commandButton value="Save" action="{!save}"/> <apex:commandButton value="Cancel" action="{!cancel}"/> </apex:pageBlockButtons> <apex:actionRegion > <apex:pageBlockSection title="Basic Information" columns="1"> <apex:inputField value="{!opportunity.name}"/> <apex:pageBlockSectionItem > <apex:outputLabel value="Stage"/> <apex:outputPanel > <apex:inputField value="{!opportunity.stageName}"> <apex:actionSupport event="onchange" rerender="thePageBlock" status="status"/> </apex:inputField> <apex:actionStatus startText="applying value..." id="status"/> </apex:outputPanel> </apex:pageBlockSectionItem> <apex:inputField value="{!opportunity.amount}"/> <apex:inputField value="{!opportunity.closedate}"/> </apex:pageBlockSection> </apex:actionRegion> <apex:pageBlockSection title="Closed Lost Information" columns="1" rendered="{!opportunity.stageName == 'Prospecting'}"> <apex:inputField value="{!opportunity.Country__c}" required="true"/> <apex:inputField value="{!opportunity.City__c}"/> </apex:pageBlockSection> <apex:pageBlockSection title="Closed Lost Information" columns="1" rendered="{!opportunity.stageName == 'Needs Analysis'}"> <apex:inputField value="{!opportunity.Country__c}" required="true"/> <apex:inputField value="{!opportunity.City__c}"/> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>
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:-
PIc 2:-
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
In screenshot 1 - I have opened a saved Opportunity. You can see Opportunity has saved values "Dallas" and "New York"
In screenshot 2 - Now if I change the stage to "Needs Analysis", page says applying values... and City field resets to default/blank.
Can you please help?
Can you check, if there is any dependent relation between Stage and City fields?
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.