+ Start a Discussion
Wayne_ClarkWayne_Clark 

How do I add a Save Button to a Visualforce page with an Extension


Hello,

 

The standard save button in my visualforce page does not save any changes I made.  I'm assuming I have to build it into the controller, but I can not find any documentation on exactly how to do this. 

 

My page creates a list where I can multiple multple records at one time, but I'm unable to save them.  Thanks in advance for any help!

 

Here is my contoller and Visualforce code:


public with sharing class InvoicePagination {
    private final Invoice__c invo;  

    public InvoicePagination(
           ApexPages.StandardSetController controller)
    {
           this.invo = (Invoice__c)controller.getRecord();
    }    
    
    public ApexPages.StandardSetController invoiceRecords{
        get {
            if(invoiceRecords == null) {
                return new ApexPages.StandardSetController(
                         Database.getQueryLocator(
                [SELECT Id, Name, Status__c,Check_Number__c,
                sales_order_number__r.Customer_Charge_Name__r.Payer__c,
                sales_order_number__r.Customer_Charge_Name__r.KCC_Order__r.Ship_Date__c,
                sales_order_number__r.Customer_Charge_Name__r.Total_Customer_Charge__c,
                sales_order_number__r.Customer_Charge_Name__r.KCC_Order__r.Name
                    FROM Invoice__c WHERE status__c = 'Open'
                    ]));
            }
            return invoiceRecords;
        }
        private set;
    }
    
    ***********************************************Visualforce Page******************************************************

    
    
    public List<Invoice__c> getInvoicePagination() {
         return (List<Invoice__c>) invoiceRecords.getRecords();
    }     
}


<apex:page standardController="Invoice__c"
           recordSetVar="invoices"
           tabStyle="Invoice__c" sidebar="false" extensions="InvoicePagination">
  <apex:form >
    <apex:pageBlock >
    
      <apex:pageMessages />
      
      <apex:pageBlockButtons >
        <apex:commandButton value="Save"
                            action="{!save}"/>
      </apex:pageBlockButtons>
      
      <apex:pageBlockTable value="{!InvoicePagination}"
                           var="inv">
 <apex:column value="{!inv.sales_order_number__r.Customer_Charge_Name__r.Payer__c}"/>
  <apex:column value="{!inv.sales_order_number__r.Customer_Charge_Name__r.KCC_Order__r.Name}"/>
 <apex:column value="{!inv.sales_order_number__r.Customer_Charge_Name__r.KCC_Order__r.Ship_Date__c}"/>
        <apex:column value="{!inv.name}"/>
        <apex:column value="{!inv.sales_order_number__r.Customer_Charge_Name__r.Total_Customer_Charge__c}"/>

        
        <apex:column headerValue="Status">
 <apex:inputField value="{!inv.Status__c}"/>
        </apex:column>
        <apex:column headerValue="Check Number">
        <apex:inputField value="{!inv.Check_Number__c}"/>
 
        </apex:column>
        
      </apex:pageBlockTable>      
            
    </apex:pageBlock>
  </apex:form>
</apex:page>







bmabma

You would need to override the default "save" action in your extension by the example below. If your purpose is just to modify data on the invalids, you can probably use the example without extensions.

 

With extensions:

 

public with sharing class InvoicePagination {
/*
your current code
*/

public void save() {
//perform the save logic here
}
}

 

 

Without extensions:

 

<apex:page standardController="Invoice__c" recordSetVar="invoices" tabStyle="Invoice__c" sidebar="false">
<apex:pageMesages/>
<apex:form >
<apex:pageBlock >
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!save}"/>
</apex:pageBlockButtons>

<apex:pageBlockTable value="{!invoices}" var="inv">
<apex:column value="{!inv.sales_order_number__r.Customer_Charge_Name__r.Payer__c}"/>
<apex:column value="{!inv.sales_order_number__r.Customer_Charge_Name__r.KCC_Order__r.Name}"/>
<apex:column value="{!inv.sales_order_number__r.Customer_Charge_Name__r.KCC_Order__r.Ship_Date__c}"/>
<apex:column value="{!inv.name}"/>
<apex:column value="{!inv.sales_order_number__r.Customer_Charge_Name__r.Total_Customer_Charge__c}"/>


<apex:column headerValue="Status">
<apex:inputField value="{!inv.Status__c}"/>
</apex:column>
<apex:column headerValue="Check Number">
<apex:inputField value="{!inv.Check_Number__c}"/>

</apex:column>

</apex:pageBlockTable>

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

 

 

 

SSRS2SSRS2

Hello 

 

<apex:page standardController="Invoice__c"
           recordSetVar="invoices"
           tabStyle="Invoice__c" sidebar="false" extensions="InvoicePagination">
...

<apex:commandButton value="Save" action="{!save}"/>

 save button only save records only if you have recordes likes

 

 <apex:inputField value="{!Invoice__c.Status__c}"/>

 

Otherwise you have to save the records overwrite the save method in your extensions 'InvoicePagination'.

 

public PageReference save() {
 /* you have to implement code for save Ex: upsert  this.invo;*/
 return null;
}

-Suresh