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
Kiyana DunlockKiyana Dunlock 

Trying to create simple vf page with date inputs that are passed back to the controller and used in the SOQL

Hi Team!!

Currently the first SOQL is working but when I update the dates and click submit I still see the same list of schedules even though they are not in the range.  Was trying to get the start week working in my code first but I need both start and end. 
 
VF Page
<apex:page standardController="Schedules__c" extensions="WeeklyComparisonController">
<script>
function toggleContacts(className){
    elem = document.getElementsByClassName(className)[0];
    if(elem.style.display == 'none')
        elem.style.display = 'block';
    else
        elem.style.display = 'none';
}
</script>
<apex:form >
<apex:panelGrid columns="5" id="dates1">
    <b>Start Date: </b><apex:inputfield value="{!firstRangeWeek.Week__c}"/>
    <b>End Date: </b><apex:inputfield value="{!Schedules__c.Week__c}"/>
    <apex:commandButton value="Submit" rerender="dates1, case"/>

</apex:panelGrid>
<apex:outputPanel id="test">  
    <apex:repeat value="{!sched}" var="s" id="scheds">
        <apex:pageBlock title="{!s.Name} {!s.Week__c} ({!s.ID})">
            Data
        </apex:pageBlock>
    </apex:repeat>
</apex:outputPanel>
</apex:form>
</apex:page>


 
Controller
 
public class WeeklyComparisonController {
    public Schedules__c firstRangeWeek{get; set;}

    public WeeklyComparisonController(ApexPages.StandardController sc){
        firstRangeWeek = new Schedules__c(Week__c = date.today().toStartofWeek().AddDays(-6));
    }
    public Schedules__c[] sched { 	
        get {
            return [
                    SELECT Id, Name, Week__c 
                    FROM Schedules__c
                    WHERE DealProgram__c = 'ION Television'
                    AND Week__c >= :date.valueOf(firstRangeWeek.Week__c)
                    ];
        }
    }
}

I know I need an action with the Submit but Im not sure how to set it up. I tries this and recieved numerous erros:

User-added imageUser-added image
Sai PraveenSai Praveen (Salesforce Developers) 
Hi,

The Errors which you are receiving is you did not Initiase sched in the second method. You only created that variable in First method . So in second method you need to query as below.
 
public void fetchScheduleList{
List<Schedules__c> sched= new List<Schedules__c>();
sched= [select id,Name,Week__c,DealProgram__c From Schedules__c where DealProgram__c='ION Television' AND Week__c>=:date.valueof(firstRangeWeek.week__c)];
}

Let me know if you face any issues.

If this solution helps, Please mark it as best answer.

Thanks,