+ Start a Discussion
ethanoneethanone 

Edit multiple records with a list controller extension

I'm trying to edit multiple records with a list controller extension. I want to use the standard controller {!Save} action, so I only need to use the extension to limit the records I want to show up in my list. The problem is that when I include the list controller extension in my VF page, my edits are not saved. Below is my code for page and extension respectively. Please let me know what I'm doing wrong. If I need to write a custom {!Save} action, please help guide me on how to do that. Thanks for your help!

Visualforce page (called customCommissionEdit):
<apex:page standardController="lda_Commission__c" recordSetVar="TheseCommissions" extensions="extCustomCommissionList">
    <apex:form >
        <apex:pageBlock >
            <apex:pageMessages ></apex:pageMessages>
            <apex:pageBlockButtons >
                <apex:commandButton value="Save" action="{!save}"/>
                <apex:commandButton value="quicksave" action="{!quicksave}"/>
                <apex:commandButton value="Cancel" action="{!cancel}"/>
            </apex:pageBlockButtons>
            <apex:pageBlockTable value="{!TheseCommissions}" var="comm">
                <apex:column value="{!comm.name}"/>
                <apex:column value="{!comm.Agent_Order__c}"/>
                <apex:column value="{!comm.Agent__c}"/>
                <apex:column value="{!comm.Comm_Dollars__c}"/>
                <apex:column value="{!comm.Comm_Pct__c}"/>
                <apex:column headerValue="Commission Percent">
                    <apex:inputField value="{!comm.Comm_Pct__c}"/>
                </apex:column>
                <apex:column value="{!comm.LAO_Agent__c}"/>
                <apex:column value="{!comm.Role__c}"/>
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>
Controller extension (called extCustomCommissionList):
public with sharing class extCustomCommissionList {

    public extCustomCommissionList(ApexPages.StandardSetController controller) {
    }

     public list<lda_Commission__c> getTheseCommissions() {
            return [SELECT DealID__c, Name, Agent__c, LAO_Agent__c, Agent_Order__c, Comm_Dollars__c, Comm_Pct__c, Fiduciary__c, Role__c FROM lda_Commission__c WHERE DealID__c = :ApexPages.currentPage().getParameters().get('id')]; 
        } 
}

The lda_Commission__c object that I'm trying to edit is a child to another object, so I just want the user to edit the related child lda_Commission__c.

 
Suneel#8Suneel#8
You need to exclusively save the collection in your controller class as you are not using default collection given by recordSetVar attribute.by definiing a new method or overriding the Save method in controller class
HaiderRaza77HaiderRaza77
Visualforce:
<apex:page standardController="Opportunity" recordSetVar="opportunities" extensions="OppsExtension">
    <apex:pagemessages ></apex:pagemessages>
    <apex:pageBlock title="Viewing Opps">
        <apex:form id="theForm">
            <apex:pageBlockSection >
                <apex:pageblockTable value="{!Opportunities}" var="opp">
                    <apex:column value="{!opp.Name}"/>
                    <apex:column >
                        <apex:inputfield value="{!opp.StageName}"/>
                    </apex:column>
                </apex:pageblockTable>
            </apex:pageBlockSection>
            <apex:panelGrid columns="2">
                <apex:commandLink action="{!previous}">Previous</apex:commandlink>
                <apex:commandLink action="{!next}">Next</apex:commandlink>
                <apex:commandButton action="{!save}" value="Save"/>
            </apex:panelGrid>
        </apex:form> 
    </apex:pageBlock>
</apex:page>

Controller:
 
public with sharing class OppsExtension {
    public ApexPages.StandardSetController OppRecords{
        get {
            if(OppRecords == null) {
                OppRecords = new ApexPages.StandardSetController(Database.getQueryLocator([SELECT Name, StageName FROM Opportunity WHERE AccountId=:ApexPages.currentPage().getParameters().get('id') ]));
            }
            return OppRecords;
        }
        private set;
    }
    
    public OppsExtension(ApexPages.StandardSetController controller) {

    }
    
    public List<Opportunity> getOpportunities(){
        return (List<Opportunity>)OppRecords.getRecords();
    }
    
    public Pagereference save(){
        OppRecords.save();
        return null;
    }

}