You need to sign in to do that
Don't have an account?
Shawn Reichner 29
Date format changes when used on Visualforce Page Search
Hello awesome devs!
I am attempting to create a VF page with 4 fields for user inputting. 2 of these fields are Date fields which when filled in like MM/DD/YYY when I press the search button to call my custom controller the date in the field populated has its format changed to Tue Dec 26 00:00:00 GMT 2017 and doesnt seem to be being applied in the search itself as all records are returned and not ones just for the date entered.
Can someone help me with gettign the format to stay as I think this is the cause of the date field not being used in the search criteria.
Please see my VF Page and controller code below.
Thank you very much for any help you can provide,
Shawn
VF Page Code -
Controller Code -
I am attempting to create a VF page with 4 fields for user inputting. 2 of these fields are Date fields which when filled in like MM/DD/YYY when I press the search button to call my custom controller the date in the field populated has its format changed to Tue Dec 26 00:00:00 GMT 2017 and doesnt seem to be being applied in the search itself as all records are returned and not ones just for the date entered.
Can someone help me with gettign the format to stay as I think this is the cause of the date field not being used in the search criteria.
Please see my VF Page and controller code below.
Thank you very much for any help you can provide,
Shawn
VF Page Code -
<apex:page controller="SubSearchController"> <apex:form> <apex:pageBlock id="pb"> <apex:pageBlockButtons> <apex:commandButton action="{!searchRecords}" value="Search" rerender="pb"/> </apex:pageBlockButtons> <apex:pageBlockSection columns="2"> <apex:outputLabel value="Account Id" /> <apex:inputText value="{!AccId}"/> <apex:outputLabel value="Status" /> <apex:inputText value="{!SubStatus}"/> <apex:outputLabel value="Service Activation date" /> <apex:inputText value="{!SAD}"/> <apex:outputLabel value="Term End Date" /> <apex:inputText value="{!TermEnd}"/> </apex:pageBlockSection> <apex:pageBlockTable var="record" value="{!records}" id="pbTable"> <apex:column value="{!record.Name}" /> <apex:column value="{!record.Zuora__Status__c}" /> <apex:column value="{!record.Zuora__ServiceActivationDate__c}" /> <apex:column value="{!record.Zuora__TermEndDate__c}" /> </apex:pageBlockTable> </apex:pageBlock> </apex:form> </apex:page>
Controller Code -
public class SubSearchController { public String AccId {get;set;} public String SubStatus {get;set;} public Date SAD {get;set;} public Date sadDate = Date.valueOf(SAD); public Date TermEnd {get;set;} public Date TermDate = Date.valueOf(TermEnd); public List<Zuora__Subscription__c> records {get; private set;} public SubSearchController(){ records = new List<Zuora__Subscription__c>(); } public PageReference searchRecords() { records = [SELECT Zuora__Account__c, Zuora__Status__c, Zuora__ServiceActivationDate__c, Zuora__TermEndDate__c, OpportunityId__c, Total_Booking_Amount__c, Id, Name FROM Zuora__Subscription__c WHERE Zuora__Account__c = : AccId AND Zuora__Status__c = : SubStatus AND (Zuora__ServiceActivationDate__c = : sadDate OR Zuora__TermEndDate__c = :TermDate)]; return null; } }
The <apex:inputText > is converting the date to text format. So using <apex:input type="date"> should solve the problem
use
All Answers
to if its a custom field. because <apex:outputField> component respects the attributes of the associated field, including how it should be displayed to the user. In this case, the value will be formatted as date.
or use,
Invalid bind expression type of String for column of type Date. Any idea how to get around that?
Shawn
The <apex:inputText > is converting the date to text format. So using <apex:input type="date"> should solve the problem
use