function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Dippan PatelDippan 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. 
<apex:pageBlockSection title="Content Section" columns="1">

      <apex:pageBlockButtons >
	    <apex:commandButton action="{!SaveRecord}" value="Save"/>
            <apex:commandButton action="{!cancel}" value="Cancel"/>

     <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}"/>

Controller code: 
public ApexPages.PageReference SaveRecord()
            insert obj;
            PageReference pr = new PageReference('/' +;
            return pr;
        catch (Exception e){
            System.debug(LoggingLevel.ERROR, e.getMessage());
            return null;

If Country has no state value, the above code gives error Required fields are missing: [State] on Save. 

AnudeepAnudeep (Salesforce Developers) 
I suggest ensuring required="true" attribute is used on apex:inputField. 
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
Dippan PatelDippan Patel
Hi Anudeep, 

Actually that is not my question. State field value will be null for some countires. In that case, how do I save state value?