You need to sign in to do that
Don't have an account?
Simon Baird
VisualForce Page. Edits not saving
Hi there, I have created a visualforce page to update records from a list view. I am able to retrieve the fields for editing but when I save it doesn't update the record. The fields I am trying to update are related to the Patient_Session__c object via a lookup relationship. Here's the VF markup
<apex:page standardcontroller="Patient_Session__c" recordSetVar="ProgressNotes" tabStyle="Patient_Session__c" sidebar="false">
<pbe:PageBlockTableEnhancerADV targetPbTableIds="Info" paginate="true" defaultPageSize="100" pageSizeOptions="5,10,20,30,40,50,100" />
<style type="text/css">
.myClass { width: 300px; }
</style>
<h1>Mass Edit Patients</h1>
<apex:form >
<apex:pageblock >
<apex:pagemessages />
<apex:pageBlockButtons >
<apex:commandButton value="Quick Save" action="{!quicksave}"/>
<apex:commandButton value="Save" action="{!save}"/>
<apex:commandButton value="Cancel" action="{!cancel}"/>
</apex:pageBlockButtons>
<apex:pageBlockSection title="Details" columns="1">
<apex:pageBlockTable value="{!selected}" var="pgn" id="details">
<apex:column headervalue="First Name">
<apex:outputField value="{!pgn.Patient__r.First_Name__c}"/>
</apex:column>
<apex:column headervalue="Last Name">
<apex:outputField value="{!pgn.Patient__r.Last_Name__c}"/>
</apex:column>
<apex:column headervalue="Patient Description">
<apex:outputField value="{!pgn.Patient__r.Patient_Description__c}"/>
</apex:column>
<apex:column headervalue="Active">
<apex:inputField value="{!pgn.Patient__r.Active__c}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
<apex:page standardcontroller="Patient_Session__c" recordSetVar="ProgressNotes" tabStyle="Patient_Session__c" sidebar="false">
<pbe:PageBlockTableEnhancerADV targetPbTableIds="Info" paginate="true" defaultPageSize="100" pageSizeOptions="5,10,20,30,40,50,100" />
<style type="text/css">
.myClass { width: 300px; }
</style>
<h1>Mass Edit Patients</h1>
<apex:form >
<apex:pageblock >
<apex:pagemessages />
<apex:pageBlockButtons >
<apex:commandButton value="Quick Save" action="{!quicksave}"/>
<apex:commandButton value="Save" action="{!save}"/>
<apex:commandButton value="Cancel" action="{!cancel}"/>
</apex:pageBlockButtons>
<apex:pageBlockSection title="Details" columns="1">
<apex:pageBlockTable value="{!selected}" var="pgn" id="details">
<apex:column headervalue="First Name">
<apex:outputField value="{!pgn.Patient__r.First_Name__c}"/>
</apex:column>
<apex:column headervalue="Last Name">
<apex:outputField value="{!pgn.Patient__r.Last_Name__c}"/>
</apex:column>
<apex:column headervalue="Patient Description">
<apex:outputField value="{!pgn.Patient__r.Patient_Description__c}"/>
</apex:column>
<apex:column headervalue="Active">
<apex:inputField value="{!pgn.Patient__r.Active__c}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
This line "<apex:inputField value="{!pgn.Patient__r.Active__c}"/>" should update Patient__r.Active__c. Would you confirm that?
can you post your controller please
public class updatePatientInfo2{
public Patient_Session__c pt {get; set;}
public Patient__c p {get; set;}
public updatePatientInfo2(ApexPages.standardController controller){
List<Patient_Session__c> pts = [select ID, Patient__r.First_Name__c, Patient__r.Patient_Description__c, Patient__r.Active__c,
Patient__r.A_1__c, Patient__r.A_Frequency__c , Patient__r.B_1__c, Patient__r.B1_Frequency__c, Patient__r.B2_Frequency__c,
Patient__r.C_1__c, Patient__r.C1_Frequency__c, Patient__r.C2_Frequency__c,
Patient__r.D_1__c, Patient__r.D1_Frequency__c, Patient__r.D2_Frequency__c, Patient__r.X__c
from Patient_Session__c WHERE Patient__c = :controller.getRecord().Id];
}
public void save(){
update pt;
}
}
and also looks like you were fetching from table and updating them(might be thats an issue too).
For data binding, the controller needs to define the data source and populate the data. In your case, you only have a single record, don't need apex:pageBlockTable. Try this: