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 experiencing difficulty using an inputfield to capture a date value on a visualforce page. The code code I am using is: 

 

        <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>                 

 

 

these pageBlockSectionItems are properly nested inside a pageblocksection, and a page block. The page is not throwing any errors, but the value is not being captured.

 

What is interesting is I am using the same code in a different component for another form and it is working just fine their. The value for Date_Needed__c is not being touched by the controller for the page in either instance. Therefore they are nearly identical, but for some reason this particular form will not accept the date selected by the user. The calender widget does appear however, and visually it appears the date is being captured. It just does not come through in the record being created.

 

Any help would be greatly appreciated, this is the only broken piece of my app and I am just trying to fix this before final deployment.

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

This issue was solved by removing the second NewForm declaration from my getNewForm method, silly mistake that caused a lot of trouble!!!

All Answers

kevoharakevohara

Are you using a controller?  Can you post that code?

Lindsay RoseLindsay Rose
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);
		 }       
	}
}

 That is the controller for the form which I am trying to capture a date value with. As you can see I am not touching the value for Date_Needed__c here at all.

goabhigogoabhigo

Can you post the VF code? Are you using showHeader="false" ? Are you using controller or extension?

Lindsay RoseLindsay Rose

First of all, thanks again to everyone trying to help. I have tried so hard to understand what is going wrong here, any help is so appreciated! 

 

Second I am using collapsible = false, also I just checked my debug logs and just before the actual saveAARF method is called the value of date_needed__c is null, even though I have selected a date.

 

08:54:53.100 (100874000)|SYSTEM_METHOD_ENTRY|[64]|System.debug(ANY)

08:54:53.100 (100939000)|USER_DEBUG|[64]|DEBUG|Date needed = null

08:54:53.100 (100971000)|SYSTEM_METHOD_EXIT|[64]|System.debug(ANY)

08:54:53.101 (101080000)|DML_BEGIN|[67]|Op:Insert|Type:Form__c|Rows:1

 

Finally, This is the contents of the visual force page:

 

 

<apex:page sidebar="false" tabStyle="Agile_Account_Request_Form__tab" >
<apex:messages />
<c:AARFComponent />
</apex:page> 

 

 

 

This is the component that sits on that page:

<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

This issue was solved by removing the second NewForm declaration from my getNewForm method, silly mistake that caused a lot of trouble!!!

This was selected as the best answer