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
Simon BairdSimon 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>
Roy LuoRoy Luo
outputFields here won't update the binding source, so need to use inputField for fields you want to update.

This line "<apex:inputField value="{!pgn.Patient__r.Active__c}"/>" should update Patient__r.Active__c. Would you confirm that? 

 
Simon BairdSimon Baird
Hi Roy, the "<apex:inputField value="{!pgn.Patient__r.Active__c}"/> does not update unfortunately and that's the issue. 
Navee RahulNavee Rahul
Hello simon,

can you post your controller please
Simon BairdSimon Baird
Hi Navee, I've had a couple of cracks at an extension without much luck. Here's one i was working on today

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;
           }
}
Navee RahulNavee Rahul
debug the Pt in save mthod simon,looks like pt doestn have Active__c values.

and also looks like you were fetching from table and updating them(might be thats an issue too).
Roy LuoRoy Luo
In your VF page, I see recordSetVar="ProgressNotes", but your controller didn't define it anywhere.

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:
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]; 

                 pt = pts.get(0);
            }

    public void save(){
        update pt;
           }
}
 
<apex:page standardcontroller="Patient_Session__c" 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:outputField value="{!pt.Patient__r.First_Name__c}"/>
            <apex:outputField value="{!pt.Patient__r.Last_Name__c}"/>
            <apex:outputField value="{!pt.Patient__r.Patient_Description__c}"/>
            <apex:inputField value="{!pt.Patient__r.Active__c}"/>

   
            </apex:pageBlockSection>   
        </apex:pageBlock>
    </apex:form>        
</apex:page>

 
Simon BairdSimon Baird
Hi Roy, Thanks for the reply. I am trying to mass edit Patient__c from the list view of Patient_Session__c that is why I was using the table.