You need to sign in to do that
Don't have an account?
Dippan Patel
Required fields are missing: [State]
Hi All,
I am having a simple visualforce page code creates a record of an object. The state and country fields are picklist and state is dependent on Country. Below inputfield tag shows proper dependency when fields are displayed but errors on save if state is null.
Controller code:
If Country has no state value, the above code gives error Required fields are missing: [State] on Save.
I am having a simple visualforce page code creates a record of an object. The state and country fields are picklist and state is dependent on Country. Below inputfield tag shows proper dependency when fields are displayed but errors on save if state is null.
<apex:pageBlockSection title="Content Section" columns="1"> <apex:pageBlockButtons > <apex:commandButton action="{!SaveRecord}" value="Save"/> <apex:commandButton action="{!cancel}" value="Cancel"/> </apex:pageBlockButtons> <apex:inputField id="Street__c" label="Street " value="{!Street__c}"/> <apex:inputField id="City__c" label="City " value="{!City__c}"/> <apex:inputField id="State__c" label="State " value="{!State__c}"/> <apex:inputField id="Country__c" label="Country " value="{!Country__c}"/> </apex:pageBlockSection>
Controller code:
public ApexPages.PageReference SaveRecord() { try{ insert obj; PageReference pr = new PageReference('/' + Obj.id); return pr; } catch (Exception e){ System.debug(LoggingLevel.ERROR, e.getMessage()); ApexPages.addMessages(e); return null; } }
If Country has no state value, the above code gives error Required fields are missing: [State] on Save.
This will make sure a value is selected from the PickList when an end-user is entering a record through the VisualForce page.
Let me know if this helps, if it does, please mark this answer as best so that others facing the same issue will find this information useful. Thank you
Actually that is not my question. State field value will be null for some countires. In that case, how do I save state value?