You need to sign in to do that
Don't have an account?
Travis Johnston
Custom VF list not saving
I am new to Visualforce Pages and Apex Classes but I am trying to create a VF page of Registrations related to a Contact ID in the URL that has 1 editable field the the user can alter. After entering a value they click Save and I am trying to make it update the records but it just refreshes the page with the field empty.
Here is my code
VF Page
Here is my code
VF Page
<apex:page standardController="Registrant__c" recordSetVar="unused" sidebar="false" extensions="contactRegistrationList"> <apex:includeScript value="{!$Resource.UtilJS}" /> <apex:form > <apex:pageBlock > <apex:pageMessages /> <apex:pageBlock > Note: All modifications made on the page will be lost if Return button is clicked without clicking the Save button first. </apex:pageBlock> <apex:pageBlockButtons > <apex:commandButton value="Save" action="{!saveList}"/> <apex:commandButton value="Return" action="{!cancel}"/> </apex:pageBlockButtons> <apex:pageBlockTable value="{!Records}" var="a" id="table"> <apex:column headerValue="Id" value="{!a.name}"/> <apex:column headerValue="Contact" value="{!a.Contact__c}"/> <apex:column headerValue="Event" value="{!a.Associated_Event__c}"/> <apex:column headerValue="Section" value="{!a.Section_del__c}"/> <apex:column headerValue="Grade" value="{!a.Grade__c}"/> <apex:column headerValue="Enter amount to credit"> <apex:inputField value="{!a.Licensure_Credit__c}"/> </apex:column> </apex:pageBlockTable> </apex:pageBlock> </apex:form> </apex:page>And the Apex Class
public class contactRegistrationList { public Registrant__c Registrant {get;set;} public contactRegistrationList(ApexPages.StandardController controller) { //Needed to stop a constructor error } public List<Registrant__c> Records { get { try { Records = new List<Registrant__c>(); Records = [SELECT id,name,Contact__c,Associated_Event__c,Grade__c,Section_del__c,Licensure_Credit__c FROM Registrant__c WHERE Contact__c = :ApexPages.currentPage().getParameters().get('contactid')]; } catch (Exception ex) { Records = null; } return Records; } private set; } public contactRegistrationList(ApexPages.StandardSetController controller){ controller.AddFields(new List<String>{'Contact__c'}); Registrant = (Registrant__c) controller.getRecord(); System.debug('***** ' + Registrant ); } public PageReference saveList(){ update Records; return null; } }
Change your property:
public List<Registrant__c> Records {get; set;}
In your controller:
public contactRegistrationList(ApexPages.StandardSetController controller){
controller.AddFields(new List<String>{'Contact__c'});
Registrant = (Registrant__c) controller.getRecord();
System.debug('***** ' + Registrant );
try
{
Records = new List<Registrant__c>();
Records = [SELECT id,name,Contact__c,Associated_Event__c,Grade__c,Section_del__c,Licensure_Credit__c FROM Registrant__c WHERE Contact__c = :ApexPages.currentPage().getParameters().get('contactid')];
}
catch (Exception ex)
{
Records = null;
}
}