+ Start a Discussion
Simon BairdSimon Baird 

How to update parent records from child list view

I need help with a controller extension to retrieve and update parent records from a list view. We have a child object called Patient_Session__c that has a lookup to parent called Patient_c and want to use a visualforce page to update the parent records in mass edit mode from a list view of the child records.  Here's the extension I am using:

public with sharing class updatePatientInfo {
    public Patient_Session__c pgn;
    public Patient__c patient;

    public updatePatientInfo(ApexPages.StandardController controller) {
        this.pgn = (Patient_Session__c)controller.getRecord();
        this.patient = [SELECT Id,Name,Patient_Description__c,A_1__c,A_Frequency__c,B_1__c,B1_Frequency__c,B2_Frequency__c,C_1__c,C1_Frequency__c,C2_Frequency__c,D_1__c,D1_Frequency__c,D2_Frequency__c,X__c FROM Patient__c WHERE ID = :ApexPages.currentPage().getParameters().get('id')];

    public PageReference saveRecord() {
    update patient;
    update pgn;  
        return null;

Here's the visualforcepage

<apex:page controller="updatePatientInfo" tabStyle="Patient_Session__c" sidebar="false">
<pbe:PageBlockTableEnhancerADV targetPbTableIds="details," paginate="true" defaultPageSize="100" pageSizeOptions="5,10,20,30,40,50,100" />
  <style type="text/css">
        .myClass { width: 300px; }
<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:pageBlockSection title="Details" columns="1">
    <apex:pageBlockTable value="{!selected}" var="pgn" id="details">
        <apex:column headervalue="First Name">
            <apex:inputField value="{!pgn.Patient__r.Patient_Description__c}"/>

When I try to save the visualforce page I get this error
 "Error: Unknown constructor 'updatePatientInfo.updatePatientInfo()"

I am new to apex so any help would be greatly appreciated
Yoganand GadekarYoganand Gadekar
See if this Mass update visualforce component can help you:
Simon BairdSimon Baird
Hi Yoganand, note quite. The code needs to put all the fields into edit mode using the visualforce markup I have used above