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
Lindsay RoseLindsay Rose 

Problems capturing date value using input field on Visual Force Page

I have been working on this issue for a few days now, trying to understand why this form will not capture the date entered using the standard salesforce functionality and date picker. What is weird is that I have another form using the exact same code to capture a date and it is working perfectly.

There are no referenced to the field in the controller for either page, yet the page that I have included below does not save the date, while the other form does.

 

This is the code for the inputfield that should store a value to NewForm.Date_Needed__c, I ripped right out of my component for the form:



 

 <apex:pageBlockSectionItem >
            <apex:outputLabel >When is the new account required by? </apex:outputLabel>
        </apex:pageBlockSectionItem>  
        
        <apex:pageBlockSectionItem >
            <apex:inputField required="true" value="{!NewForm.Date_Needed__c}"/>
        </apex:pageBlockSectionItem>  

 The only difference in the use of the code snippet between forms is placement. This is the second set of pageblocksection items in the pageblocksection for the form I am having trouble with, while the other form has it as the last set of items before the pageblocksection is closed. Any help would be appreciated, I understand this isnt much to go off of, I will upload my component and controller if anybody would find it helpful. I am hoping there is something wrong with this snippet, making this problem an easy fix.

Best Answer chosen by Admin (Salesforce Developers) 
Lindsay RoseLindsay Rose

For anyone else who happens to run into a similiar issue, the solution was actually simple. I was creating TWO new forms in my code, one amongst the variables declared at the top of my controller, and another in the getNewForm method, when I removed the second declaration from the getNewForm method, and simply instantiated the first form object, the date value was passed to my controller as expected.

 

The issue explained in the simplest way possible was that I was creating a new form, setting the Date Needed value, then creating another new form with all the rest of the data and that is why the date was not being stored.

All Answers

navneetnavneet

share the complete page.. remove required='true' and use <Inputtext> insted of <inputField>

 

if it will not work then share the page .. will try it..

Lindsay RoseLindsay Rose

Navneet,

 

I have removed the required attribute and changed the inputField to an inputText. The value is still not being stored. 

 

Visual Force Page:

 

<apex:page sidebar="false" tabStyle="Agile_Account_Request_Form__tab" >

<apex:messages />

<c:AARFComponent />  

</apex:page>

 

Controller:

public class AARFController {

    public String AccountToModel{ get; set; }
    public String AccountType { get; set; }
    public String AdditionalRole{ get; set; }
    public Boolean Approved { get; set; }	
    public Form__c CompleteForm = new Form__c();
    public Boolean done { get; set; }  
    public String FormName { get; set; }
    public User Manager;    
    public Form__c MasterForm;
    public Boolean ModelAfterExisting{ get; set; }  
    public Form__c NewForm = new Form__c(); 
    public String Purpose { get; set; }
    public String RecordID { get; set; }
    public String RecordTypeID { get; set; }
    public String RequestType { get; set; }
    public String RoleForAccount{ get; set; } 
        
	public User getManager() 
	{  
		if(Manager == null)    
		{       Id userId = userInfo.getUserId(); 
				User userObj = [select id, managerId, name from User where id=:userId];
				Manager =[select id, name, phone, email from User where id =:userObj.managerId];
		}
		return Manager;
	}   

	public Form__c getMasterForm()
	{         
		MasterForm = [SELECT Name__c, Purpose__c FROM Form__c WHERE Name = 'Agile Account' ];
		FormName = MasterForm.Name__c;
		Purpose = MasterForm.Purpose__c;       
		return MasterForm;
	}         
         
	public Form__c getNewForm() 
	{
		Form__c NewForm = new Form__c();
		return NewForm;
	}
	
	public Form__c getCompleteForm()
	{
		CompleteForm = [SELECT Approval_Complete__c, Name, Name__c FROM Form__c WHERE Id = :RecordID]; 
		return CompleteForm;
	}
			
	public void saveAARF()
	{   
		NewForm.RecordTypeId = '012T00000004sYKIAY';
		NewForm.Account_Type__c = AccountType;  
		NewForm.Additional_Role_For_Account__c = AdditionalRole;
		NewForm.Model_After_Existing_Account__c = ModelAfterExisting;
		
		if (ModelAfterExisting == true)
		{NewForm.Account_To_Model__c = AccountToModel;} 
		else {NewForm.Account_To_Model__c = '';}
		
		NewForm.Requested_By__c = userInfo.getUserId(); 
		NewForm.Role_For_Account__c = RoleForAccount;
		
		try
		 {
			insert NewForm;
			RecordID = NewForm.Id;
			Done = true;
		 }
		catch(DmlException ex)
		 {
			ApexPages.addMessages(ex);
		 }       
}
}

Component:

<apex:component controller="AARFController" allowDML="true">
<apex:form >

<apex:pageBlock rendered="NOT({!$ObjectType.User.accessible})" title="Sorry, but there was a problem accessing the data required to complete this form. Please ensure you are logged in with the correct Username, and contact your system administrator if the problem persists."/> 

<apex:pageBlock rendered="{!done = false}" >

<apex:pageBlockButtons >
    <apex:commandButton action="{!saveAARF}" value="Save and Review" rendered="{!done = false}"/>
</apex:pageBlockButtons>

<apex:pageBlockSection title="{!MasterForm.Name__c}" columns="1" collapsible="false">

    <apex:pageBlockSectionItem >
        {!MasterForm.Purpose__c}
    </apex:pageBlockSectionItem>
    
</apex:pageBlockSection>            

<c:UserInfoComponent />

    <apex:pageBlockSection title="Account Information" collapsible="false">
    
        <apex:pageBlockSectionItem >
            <apex:outputLabel >What type of Account request is this? </apex:outputLabel>
        </apex:pageBlockSectionItem> 
        
        <apex:pageBlockSectionItem >
            <apex:selectList value="{!AccountType}" size="1"  style="width: 300px;">
                <apex:selectOption itemLabel="Request for New Account" itemValue="New Account"/>
                <apex:selectOption itemLabel="Request to Change Existing Account" itemValue="Change Existing Account"/>
            </apex:selectList>  
        </apex:pageBlockSectionItem>
        
        <apex:pageBlockSectionItem >
            <apex:outputLabel >When is the new account required by? </apex:outputLabel>
        </apex:pageBlockSectionItem>  
        
        <apex:pageBlockSectionItem >
            <apex:inputField required="true" value="{!NewForm.Date_Needed__c}"/>
        </apex:pageBlockSectionItem> 
                
        <apex:pageBlockSectionItem >
            <apex:outputLabel >What is the primary role of the account?</apex:outputLabel>
        </apex:pageBlockSectionItem>
        
        <apex:pageBlockSectionItem >
            <apex:selectList value="{!RoleforAccount}" size="1"  style="width: 300px;">
                <apex:selectOption itemLabel="Read Only" itemValue="Read Only"/>
                <apex:selectOption itemLabel="Change Approval" itemValue="Change Approval"/>
                <apex:selectOption itemLabel="Component Engineer" itemValue="Component Engineer"/>
                <apex:selectOption itemLabel="Contract Manufacturer" itemValue="Contract Manufacturer"/>
                <apex:selectOption itemLabel="Documentation" itemValue="Documentation"/>
                <apex:selectOption itemLabel="Engineering" itemValue="Engineering"/>
                <apex:selectOption itemLabel="Finance" itemValue="Finance"/>
                <apex:selectOption itemLabel="GTAC" itemValue="GTAC"/>
                <apex:selectOption itemLabel="Mechanical Engineer" itemValue="Mechanical Engineer"/>
                <apex:selectOption itemLabel="New Product Engineer" itemValue="New Product Engineer"/>
                <apex:selectOption itemLabel="Quality" itemValue="Quality"/>
                <apex:selectOption itemLabel="Supply Chain" itemValue="Supply Chain"/>
                <apex:selectOption itemLabel="Supply Chain Materials" itemValue="Supply Chain Materials"/>
            </apex:selectList>  
        </apex:pageBlockSectionItem>
        
        <apex:pageBlockSectionItem >
            <apex:outputLabel >What is the additional role of the account?</apex:outputLabel>
        </apex:pageBlockSectionItem>
        
        <apex:pageBlockSectionItem >        
            <apex:selectList value="{!AdditionalRole}" size="1"  style="width: 300px;">               
                <apex:selectOption itemLabel="Read Only" itemValue="Read Only"/>
                <apex:selectOption itemLabel="Change Approval" itemValue="Change Approval"/>
                <apex:selectOption itemLabel="Component Engineer" itemValue="Component Engineer"/>
                <apex:selectOption itemLabel="Contract Manufacturer" itemValue="Contract Manufacturer"/>
                <apex:selectOption itemLabel="Documentation" itemValue="Documentation"/>
                <apex:selectOption itemLabel="Engineering" itemValue="Engineering"/>
                <apex:selectOption itemLabel="Finance" itemValue="Finance"/>
                <apex:selectOption itemLabel="GTAC" itemValue="GTAC"/>
                <apex:selectOption itemLabel="Mechanical Engineer" itemValue="Mechanical Engineer"/>
                <apex:selectOption itemLabel="New Product Engineer" itemValue="New Product Engineer"/>
                <apex:selectOption itemLabel="Quality" itemValue="Quality"/>
                <apex:selectOption itemLabel="Supply Chain" itemValue="Supply Chain"/>
                <apex:selectOption itemLabel="Supply Chain Materials" itemValue="Supply Chain Materials"/>
            </apex:selectList>               
        </apex:pageBlockSectionItem>       
    
        <apex:pageBlockSectionItem >
            <apex:outputLabel >Should the account be modeled after another?</apex:outputLabel>
        </apex:pageBlockSectionItem>

        <apex:pageBlockSectionItem >
            <apex:inputCheckbox value="{!ModelAfterExisting}" title="Yes, it should" /> 
        </apex:pageBlockSectionItem>
        
        <apex:pageBlockSectionItem >
            <apex:outputLabel >If so, what account should the account be modeled after?</apex:outputLabel>
        </apex:pageBlockSectionItem>
                
        <apex:pageBlockSectionItem >
            <apex:inputText value="{!AccountToModel}" style="width:300px"/>
        </apex:pageBlockSectionItem>
        
    </apex:pageBlockSection>
    
</apex:pageBlock>
 
<apex:pageBlock rendered="{!done=true}"  title="{!MasterForm.Name__c}">
    
    <apex:pageBlockSection columns="1" title="{!CompleteForm.Name}" id="approvedcomplete" rendered="{!CompleteForm.Approval_Complete__c == false}" collapsible="false">
        You have sucessfully completed the {!MasterForm.Name__c}!
        
        <apex:pageBlockSectionitem >
            <apex:outputLabel >Please review the information below and click "Submit for Approval" to begin the approval process. You will receive an email when your request is approved/rejected.</apex:outputLabel>
        </apex:pageBlockSectionItem> 
        
        <apex:pageBlockSectionItem >    
            <apex:commandLink reRender="approvedcomplete">
                <apex:detail subject="{!RecordID}"/>
            </apex:commandLink>
        </apex:pageBlockSectionItem>
        
    </apex:pageBlockSection>

    <apex:pageBlockSection columns="1" rendered="{!CompleteForm.Approval_Complete__c == true}" collapsible="false">
        {!CompleteForm.Name} was approved automatically, you should receive an email soon from the service desk confirming it was received.
    </apex:pageBlockSection>
    
</apex:pageBlock>

</apex:form>
</apex:component>
Lindsay RoseLindsay Rose

For anyone else who happens to run into a similiar issue, the solution was actually simple. I was creating TWO new forms in my code, one amongst the variables declared at the top of my controller, and another in the getNewForm method, when I removed the second declaration from the getNewForm method, and simply instantiated the first form object, the date value was passed to my controller as expected.

 

The issue explained in the simplest way possible was that I was creating a new form, setting the Date Needed value, then creating another new form with all the rest of the data and that is why the date was not being stored.

This was selected as the best answer