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
FL blondieFL blondie 

VF Page always creates new record

My first attempt at coding and just can't make it work.  All I need is to pull records for a particular day, from a preload table and update the volume counts.  When I click on save or enter the date it creates a new record.  How  can I fix this?  

Here is the code:

public class RescueCountExtension {

    private final Rescue_count__c acct;

    public RescueCountExtension(ApexPages.StandardController stdController) {
        this.acct = (Rescue_count__c)stdController.getRecord();
 
   }
public Date SelectedDate {get;set;}

List<Rescue_Count__c> theDaysRecords;

Public List<Rescue_Count__c> getTheDaysRecords(){
   if(theDaysRecords == null){
      theDaysRecords = [SELECT Donor__c, Rescue_Date__c, BR__C, BU__c, BA__c, TA__c, BA_Bulk__C, TA_Bulk__C,Produce__c, Meat_Deli__c, Shelf_Stable__c, Non_Food__c from Rescue_count__c Order by Donor__c ];
}
return theDaysRecords;   
       
    }
}


//THE PAGE:
<apex:page standardController="Rescue_Count__c" extensions="RescueCountExtension" sidebar="false">

  
<apex:sectionheader title="Mass Edit Rescue Counts" />
<apex:form >

<apex:pageBlock title="Rescue Counts" rendered="true" mode="edit" >
<apex:pageMessages />

Note: All modifications made on the page will be lost if Return button is clicked without clicking the Save button first.

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

<apex:pageBlockSection title="Records to Update"
collapsible="false">
<apex:outputLabel value="Select Date"/>

<apex:inputText value="{!SelectedDate}" size="10" id="queryDate" onfocus="DatePicker.pickDate(false, this, false);" />
  <apex:actionSupport event="onchange" rerender="thetable"/>

</apex:pageBlockSection>

<apex:pageBlockTable value="{!theDaysRecords}" var="a" id="thetable">
<apex:column headerValue="Donor">
<apex:outputField value="{!a.Donor__c}"/>
</apex:column>
<apex:column headerValue="Date">
<apex:outputField value="{!a.Rescue_Date__c}"/>
</apex:column>
<apex:column headerValue="BR">
<apex:inputField value="{!a.BR__c}"/>
</apex:column>
<apex:column headerValue="BU">
<apex:inputField value="{!a.BU__c}"/>
</apex:column>
<apex:column headerValue="BA">
<apex:inputField value="{!a.BA__c}"/>
</apex:column>
<apex:column headerValue="TA">
<apex:inputField value="{!a.TA__c}"/>
</apex:column>
<apex:column headerValue="BA_Bulk">
<apex:inputField value="{!a.BA_Bulk__c}"/>
</apex:column>
<apex:column headerValue="TA_Bulk">
<apex:inputField value="{!a.TA_Bulk__c}"/>
</apex:column>
<apex:column headerValue="Produce">
<apex:inputField value="{!a.Produce__c}"/>
</apex:column>
<apex:column headerValue="Meat/Deli">
<apex:inputField value="{!a.Meat_Deli__c}"/>
</apex:column>
<apex:column headerValue="Shelf Stable">
<apex:inputField value="{!a.Shelf_Stable__c}"/>
</apex:column>
<apex:column headerValue="Non_Food">
<apex:inputField value="{!a.Non_Food__c}"/>
</apex:column>
</apex:pageBlockTable>

</apex:pageBlock>
</apex:form>
</apex:page>
manhnt.bkitmanhnt.bkit
Hi FL blondie, What do you want to fix?
You can email me at manhnt.bkit@gmail.com, I will help you.

Manh, 
Vinit_KumarVinit_Kumar
In your controller,I don't see you doing any update.so,the Save method would work as standard save method and woull always save a new records.

If you want to perform any update on a single/ list of records,you should create another method inside your controller,query that record and then update it explicitly.

And,on Click of command button you should be calling that method.

Hope this helps !!
FL blondieFL blondie
Ok... I have changed the save to a savetherecords function and not getting the new record added.  But how do you code to loop through the record set, theDaysRecords, and update each record?

Also, the onchange or onenter of the date in the datepicker is not pulling the records.  Why?  
here is the updated code.  If i hard code or leave off the where clause it pulls the records.

Public List<Rescue_Count__c> getTheDaysRecords(){
   if(theDaysRecords == null){
      theDaysRecords = [SELECT Donor__c, Rescue_Date__c, BR__C, BU__c, BA__c, TA__c, BA_Bulk__C, TA_Bulk__C,Produce__c, Meat_Deli__c, Shelf_Stable__c, Non_Food__c from Rescue_count__c where Rescue_date__c = :selecteddate Order by Donor__c ];
}
return theDaysRecords;   
       
    }