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
BenBurbridge(JP)BenBurbridge(JP) 

Custom Save Button

I have created a visualforce page for my finance team to work specifically with some integrated fields, I have pasted my code below (please excuse the way it is laid out as I am new and learning)
 
<apex:page standardController="Treatment_Plan__c" extensions="BillingTreatmentPlanController" title="Billing Department - Treatment Plan" standardStylesheets="false" tabstyle="Treatment_Plan__c">

<script type="text/javascript">
    window.onload=function(){
    var tfrow = document.getElementById('tfhover').rows.length;
    var tbRow=[];
    for (var i=1;i<tfrow;i++) {
        tbRow[i]=document.getElementById('tfhover').rows[i];
        tbRow[i].onmouseover = function(){
          this.style.backgroundColor = '#f3f8aa';
        };
        tbRow[i].onmouseout = function() {
          this.style.backgroundColor = '#ffffff';
        };
    }
};
</script>

<style type="text/css">

h1 { 
    display: block;
    font-size: 18pt;
    font-family: sans-serif,arial;
    font-weight: bold;
    text-align:center;
}

table.tftable {
                font-size:12px;
                color:#333333;
                width:100%;
                border-width: 1px;
                border-color: #729ea5;
                border-collapse: collapse;
}

table.tftable th {
                    font-size:12px;background-color:#acc8cc;
                    border-width:1px;
                    padding:8px;
                    border-style:solid;
                    border-color:#729ea5;
                    text-align:left;
}

table.tftable tr {
                    background-color:#ffffff;
}

table.tftable td {
                    font-size:12px;
                    border-width: 1px;
                    padding: 8px;
                    border-style: solid;
                    border-color: #729ea5;
}

table.tftable1 {
                font-size:12px;
                color:#333333;
                width:10%;
                border-width: 1px;
                border-color: #729ea5;
                border-collapse: collapse;
}

table.tftable1 th {
                    font-size:12px;background-color:#acc8cc;
                    border-width:1px;
                    padding:8px;
                    border-style:solid;
                    border-color:#729ea5;
                    text-align:center;
}

table.tftable1 tr {
                    background-color:#ffffff;
}

table.tftable1 td {
                    font-size:12px;
                    border-width: 1px;
                    padding: 8px;
                    border-style: solid;
                    border-color: #729ea5;
                    text-align:center;
}

table.tftable2 {
                font-size:12px;
                color:#333333;
                width:20%;
                border-width: 1px;
                border-color: #729ea5;
                border-collapse: collapse;
}

table.tftable2 th {
                    font-size:12px;background-color:#acc8cc;
                    border-width:1px;
                    padding:8px;
                    border-style:solid;
                    border-color:#729ea5;
                    text-align:left;
}

table.tftable2 tr {
                    background-color:#ffffff;
}

table.tftable2 td {
                    font-size:12px;
                    border-width: 1px;
                    padding: 8px;
                    border-style: solid;
                    border-color: #729ea5;
}

</style>

<h1>Billing Department - Send OCF</h1>
    <apex:form >
        <apex:pageBlock title="Patient Details" mode="detail">
            <apex:pageBlockSection columns="1">
                <apex:inputField value="{!Treatment_Plan__c.Name}" label="Related Treatment Plan"/>
                <apex:outputText value="{!Treatment_Plan__c.Patient_First_Name__c + ' ' + Treatment_Plan__c.Patient_Last_Name__c}" label="Patients Name"/>
                <apex:outputField value="{!Treatment_Plan__c.Clinic_Check__c}" label="Clinic Used"/>
            </apex:pageBlockSection>
        </apex:pageBlock>
        <apex:pageBlock title="Service Code Lookup" mode="edit">
            <apex:pageBlockSection columns="1">
                <apex:outputText value="Copy the service code from the appropriate line below and check the corresponding check box to update that line"></apex:outputText>
                <br></br>
                <apex:inputfield value="{!Treatment_Plan__c.Service_Code1_lookup__c}" label=""/>
                <br></br>
            </apex:pageBlockSection>
        </apex:pageBlock>
        <apex:pageBlock title="Service Invoice Lines" mode="edit">
            <table id="tfhover" class="tftable" border="1">
                  <br></br>
                    <tr>    
                        <th>Line Number</th>
                        <th>Service Code</th>
                        <th>Quantity</th>
                        <th>Proposed Count</th>
                        <th>Proposed Cost</th>
                        <th>Service HST</th>
                        <th>Confirm Line</th>
                    </tr>
                    <tr style="display: {!IF(ISBLANK(Treatment_Plan__c.Service_Code_1__c), 'none', 'table-row')};">
                        <td>1</td>
                        <td><apex:inputfield value="{!Treatment_Plan__c.Service_Code_1__c}" label=""/></td>
                        <td><apex:outputfield value="{!Treatment_Plan__c.Quantity1__c}" label=""/></td>
                        <td><apex:outputfield value="{!Treatment_Plan__c.Proposed_Count_1__c}" label=""/></td>
                        <td><apex:outputfield value="{!Treatment_Plan__c.Proposed_Cost_1__c}" label=""/></td>
                        <td><apex:outputfield value="{!Treatment_Plan__c.Service_HST1__c}" label=""/></td>
                        <td><apex:inputfield value="{!Treatment_Plan__c.Update_OCF18_Cost1__c}" label=""/></td>
                    </tr>
                    <tr style="display: {!IF(ISBLANK(Treatment_Plan__c.Service_Code_2__c), 'none', 'table-row')};">
                        <td>2</td>
                        <td><apex:inputfield value="{!Treatment_Plan__c.Service_Code_2__c}" label=""/></td>
                        <td><apex:outputfield value="{!Treatment_Plan__c.Quantity2__c}" label=""/></td>
                        <td><apex:outputfield value="{!Treatment_Plan__c.Proposed_Count_2__c}" label=""/></td>
                        <td><apex:outputfield value="{!Treatment_Plan__c.Proposed_Cost_2__c}" label=""/></td>
                        <td><apex:outputfield value="{!Treatment_Plan__c.Service_HST2__c}" label=""/></td>
                        <td><apex:inputfield value="{!Treatment_Plan__c.Update_OCF18_Cost2__c}" label=""/></td>
                    </tr>
                    <tr style="display: {!IF(ISBLANK(Treatment_Plan__c.Service_Code_3__c), 'none', 'table-row')};">
                        <td>3</td>
                        <td><apex:inputfield value="{!Treatment_Plan__c.Service_Code_3__c}" label=""/></td>
                        <td><apex:outputfield value="{!Treatment_Plan__c.Quantity3__c}" label=""/></td>
                        <td><apex:outputfield value="{!Treatment_Plan__c.Proposed_Count_3__c}" label=""/></td>
                        <td><apex:outputfield value="{!Treatment_Plan__c.Proposed_Cost_3__c}" label=""/></td>
                        <td><apex:outputfield value="{!Treatment_Plan__c.Service_HST3__c}" label=""/></td>
                        <td><apex:inputfield value="{!Treatment_Plan__c.Update_OCF18_Cost3__c}" label=""/></td>  
                    </tr>
                    <tr style="display: {!IF(ISBLANK(Treatment_Plan__c.Service_Code_4__c), 'none', 'table-row')};">
                        <td>4</td>
                        <td><apex:inputfield value="{!Treatment_Plan__c.Service_Code_4__c}" label=""/></td>
                        <td><apex:outputfield value="{!Treatment_Plan__c.Quantity4__c}" label=""/></td>
                        <td><apex:outputfield value="{!Treatment_Plan__c.Proposed_Count_4__c}" label=""/></td>
                        <td><apex:outputfield value="{!Treatment_Plan__c.Proposed_Cost_4__c}" label=""/></td>
                        <td><apex:outputfield value="{!Treatment_Plan__c.Service_HST4__c}" label=""/></td>
                        <td><apex:inputfield value="{!Treatment_Plan__c.Update_OCF18_Cost4__c}" label=""/></td>
                    </tr>
                    <tr style="display: {!IF(ISBLANK(Treatment_Plan__c.Service_Code_5__c), 'none', 'table-row')};">
                        <td>5</td>
                        <td><apex:inputfield value="{!Treatment_Plan__c.Service_Code_5__c}" label=""/></td>
                        <td><apex:outputfield value="{!Treatment_Plan__c.Quantity5__c}" label=""/></td>
                        <td><apex:outputfield value="{!Treatment_Plan__c.Proposed_Count_5__c}" label=""/></td>
                        <td><apex:outputfield value="{!Treatment_Plan__c.Proposed_Cost_5__c}" label=""/></td>
                        <td><apex:outputfield value="{!Treatment_Plan__c.Service_HST5__c}" label=""/></td>
                        <td><apex:inputfield value="{!Treatment_Plan__c.Update_OCF18_Cost5__c}" label=""/></td>
                    </tr>
                    <tr style="display: {!IF(ISBLANK(Treatment_Plan__c.Service_Code_6__c), 'none', 'table-row')};">
                        <td>6</td>
                        <td><apex:inputfield value="{!Treatment_Plan__c.Service_Code_6__c}" label=""/></td>
                        <td><apex:outputfield value="{!Treatment_Plan__c.Quantity6__c}" label=""/></td>
                        <td><apex:outputfield value="{!Treatment_Plan__c.Proposed_Count_6__c}" label=""/></td>
                        <td><apex:outputfield value="{!Treatment_Plan__c.Proposed_Cost_6__c}" label=""/></td>
                        <td><apex:outputfield value="{!Treatment_Plan__c.Service_HST6__c}" label=""/></td>
                        <td><apex:inputfield value="{!Treatment_Plan__c.Update_OCF18_Cost6__c}" label=""/></td>
                    </tr>
                    <tr style="display: {!IF(ISBLANK(Treatment_Plan__c.Service_Code_7__c), 'none', 'table-row')};">
                        <td>7</td>
                        <td><apex:inputfield value="{!Treatment_Plan__c.Service_Code_7__c}" label=""/></td>
                        <td><apex:outputfield value="{!Treatment_Plan__c.Quantity7__c}" label=""/></td>
                        <td><apex:outputfield value="{!Treatment_Plan__c.Proposed_Count_7__c}" label=""/></td>
                        <td><apex:outputfield value="{!Treatment_Plan__c.Proposed_Cost_7__c}" label=""/></td>
                        <td><apex:outputfield value="{!Treatment_Plan__c.Service_HST7__c}" label=""/></td>
                        <td><apex:inputfield value="{!Treatment_Plan__c.Update_OCF18_Cost7__c}" label=""/></td>
                    </tr>
                    <tr style="display: {!IF(ISBLANK(Treatment_Plan__c.Service_Code_8__c), 'none', 'table-row')};">
                        <td>8</td>
                        <td><apex:inputfield value="{!Treatment_Plan__c.Service_Code_8__c}" label=""/></td>
                        <td><apex:outputfield value="{!Treatment_Plan__c.Quantity8__c}" label=""/></td>
                        <td><apex:outputfield value="{!Treatment_Plan__c.Proposed_Count_8__c}" label=""/></td>
                        <td><apex:outputfield value="{!Treatment_Plan__c.Proposed_Cost_8__c}" label=""/></td>
                        <td><apex:outputfield value="{!Treatment_Plan__c.Service_HST8__c}" label=""/></td>
                        <td><apex:inputfield value="{!Treatment_Plan__c.Update_OCF18_Cost8__c}" label=""/></td>
                    </tr>
                    <tr style="display: {!IF(ISBLANK(Treatment_Plan__c.Service_Code_9__c), 'none', 'table-row')};">
                        <td>9</td>
                        <td><apex:inputfield value="{!Treatment_Plan__c.Service_Code_9__c}" label=""/></td>
                        <td><apex:outputfield value="{!Treatment_Plan__c.Quantity9__c}" label=""/></td>
                        <td><apex:outputfield value="{!Treatment_Plan__c.Proposed_Count_9__c}" label=""/></td>
                        <td><apex:outputfield value="{!Treatment_Plan__c.Proposed_Cost_9__c}" label=""/></td>
                        <td><apex:outputfield value="{!Treatment_Plan__c.Service_HST9__c}" label=""/></td>
                        <td><apex:inputfield value="{!Treatment_Plan__c.Update_OCF18_Cost9__c}" label=""/></td>
                    </tr>
                    <tr style="display: {!IF(ISBLANK(Treatment_Plan__c.Service_Code_10__c), 'none', 'table-row')};">
                        <td>10</td>
                        <td><apex:inputfield value="{!Treatment_Plan__c.Service_Code_10__c}" label=""/></td>
                        <td><apex:outputfield value="{!Treatment_Plan__c.Quantity10__c}" label=""/></td>
                        <td><apex:outputfield value="{!Treatment_Plan__c.Proposed_Count_10__c}" label=""/></td>
                        <td><apex:outputfield value="{!Treatment_Plan__c.Proposed_Cost_10__c}" label=""/></td>
                        <td><apex:outputfield value="{!Treatment_Plan__c.Service_HST10__c}" label=""/></td>
                        <td><apex:inputfield value="{!Treatment_Plan__c.Update_OCF18_Cost10__c}" label=""/></td>
                    </tr>
             </table>
            <apex:pageBlockButtons location="bottom">
               <apex:commandButton id="quicksave" value="Update" action="{!quicksave}"/>
           </apex:pageBlockButtons>
           </apex:pageblock>
           <apex:pageBlock title="Product Invoice Lines" mode="edit">         
            <table id="tfhover" class="tftable" border="1">
                  <br></br>
                    <tr>
                        <th>Line Number</th>
                        <th>Product Code</th>
                        <th>Quantity</th>
                        <th>Provider Occupation</th>
                        <th>Total Count</th>
                        <th>Cost</th>
                    </tr>
                    <tr style="display: {!IF(ISBLANK(Treatment_Plan__c.Product_Code1__c), 'none', 'table-row')};">
                        <td>1</td>
                        <td><apex:inputfield value="{!Treatment_Plan__c.Product_Code1__c}" label=""/></td>
                        <td><apex:outputfield value="{!Treatment_Plan__c.Product_Quantity1__c}" label=""/></td>
                        <td><apex:outputfield value="{!Treatment_Plan__c.Product_Provider_Occupation1__c}" label=""/></td>
                        <td><apex:outputfield value="{!Treatment_Plan__c.Product_Count1__c}" label=""/></td>
                        <td><apex:inputfield value="{!Treatment_Plan__c.Product_Cost1__c}" label=""/></td>
                    </tr>
                    <tr style="display: {!IF(ISBLANK(Treatment_Plan__c.Product_Code2__c), 'none', 'table-row')};">
                        <td>2</td>
                        <td><apex:inputfield value="{!Treatment_Plan__c.Product_Code2__c}" label=""/></td>
                        <td><apex:outputfield value="{!Treatment_Plan__c.Product_Quantity2__c}" label=""/></td>
                        <td><apex:outputfield value="{!Treatment_Plan__c.Product_Provider_Occupation2__c}" label=""/></td>
                        <td><apex:outputfield value="{!Treatment_Plan__c.Product_Count2__c}" label=""/></td>
                        <td><apex:outputfield value="{!Treatment_Plan__c.Product_Cost2__c}" label=""/></td>
                    </tr>
                    <tr style="display: {!IF(ISBLANK(Treatment_Plan__c.Product_Code3__c), 'none', 'table-row')};">
                        <td>3</td>
                        <td><apex:inputfield value="{!Treatment_Plan__c.Product_Code3__c}" label=""/></td>
                        <td><apex:outputfield value="{!Treatment_Plan__c.Product_Quantity3__c}" label=""/></td>
                        <td><apex:outputfield value="{!Treatment_Plan__c.Product_Provider_Occupation3__c}" label=""/></td>
                        <td><apex:outputfield value="{!Treatment_Plan__c.Product_Count3__c}" label=""/></td>
                        <td><apex:outputfield value="{!Treatment_Plan__c.Product_Cost3__c}" label=""/></td>
                    </tr>
                    <tr style="display: {!IF(ISBLANK(Treatment_Plan__c.Product_Code4__c), 'none', 'table-row')};">
                        <td>4</td>
                        <td><apex:inputfield value="{!Treatment_Plan__c.Product_Code4__c}" label=""/></td>
                        <td><apex:outputfield value="{!Treatment_Plan__c.Product_Quantity4__c}" label=""/></td>
                        <td><apex:outputfield value="{!Treatment_Plan__c.Product_Provider_Occupation4__c}" label=""/></td>
                        <td><apex:outputfield value="{!Treatment_Plan__c.Product_Count4__c}" label=""/></td>
                        <td><apex:outputfield value="{!Treatment_Plan__c.Product_Cost4__c}" label=""/></td>
                    </tr>
                    <tr style="display: {!IF(ISBLANK(Treatment_Plan__c.Product_Code5__c), 'none', 'table-row')};">
                        <td>5</td>
                        <td><apex:inputfield value="{!Treatment_Plan__c.Product_Code5__c}" label=""/></td>
                        <td><apex:outputfield value="{!Treatment_Plan__c.Product_Quantity5__c}" label=""/></td>
                        <td><apex:outputfield value="{!Treatment_Plan__c.Product_Provider_Occupation5__c}" label=""/></td>
                        <td><apex:outputfield value="{!Treatment_Plan__c.Product_Count5__c}" label=""/></td>
                        <td><apex:outputfield value="{!Treatment_Plan__c.Product_Cost5__c}" label=""/></td>
                    </tr>
                    <tr style="display: {!IF(ISBLANK(Treatment_Plan__c.Product_Code6__c), 'none', 'table-row')};">
                        <td>6</td>
                        <td><apex:inputfield value="{!Treatment_Plan__c.Product_Code6__c}" label=""/></td>
                        <td><apex:outputfield value="{!Treatment_Plan__c.Product_Quantity6__c}" label=""/></td>
                        <td><apex:outputfield value="{!Treatment_Plan__c.Product_Provider_Occupation6__c}" label=""/></td>
                        <td><apex:outputfield value="{!Treatment_Plan__c.Product_Count6__c}" label=""/></td>
                        <td><apex:outputfield value="{!Treatment_Plan__c.Product_Cost6__c}" label=""/></td>
                    </tr>
                    <tr style="display: {!IF(ISBLANK(Treatment_Plan__c.Product_Code7__c), 'none', 'table-row')};">
                        <td>7</td>
                        <td><apex:inputfield value="{!Treatment_Plan__c.Product_Code7__c}" label=""/></td>
                        <td><apex:outputfield value="{!Treatment_Plan__c.Product_Quantity7__c}" label=""/></td>
                        <td><apex:outputfield value="{!Treatment_Plan__c.Product_Provider_Occupation7__c}" label=""/></td>
                        <td><apex:outputfield value="{!Treatment_Plan__c.Product_Count7__c}" label=""/></td>
                        <td><apex:outputfield value="{!Treatment_Plan__c.Product_Cost7__c}" label=""/></td>
                    </tr>
                    <tr style="display: {!IF(ISBLANK(Treatment_Plan__c.Product_Code8__c), 'none', 'table-row')};">
                        <td>8</td>
                        <td><apex:inputfield value="{!Treatment_Plan__c.Product_Code8__c}" label=""/></td>
                        <td><apex:outputfield value="{!Treatment_Plan__c.Product_Quantity8__c}" label=""/></td>
                        <td><apex:outputfield value="{!Treatment_Plan__c.Product_Provider_Occupation8__c}" label=""/></td>
                        <td><apex:outputfield value="{!Treatment_Plan__c.Product_Count8__c}" label=""/></td>
                        <td><apex:outputfield value="{!Treatment_Plan__c.Product_Cost8__c}" label=""/></td>
                    </tr>
                    <tr style="display: {!IF(ISBLANK(Treatment_Plan__c.Product_Code9__c), 'none', 'table-row')};">
                        <td>9</td>
                        <td><apex:inputfield value="{!Treatment_Plan__c.Product_Code9__c}" label=""/></td>
                        <td><apex:outputfield value="{!Treatment_Plan__c.Product_Quantity9__c}" label=""/></td>
                        <td><apex:outputfield value="{!Treatment_Plan__c.Product_Provider_Occupation9__c}" label=""/></td>
                        <td><apex:outputfield value="{!Treatment_Plan__c.Product_Count9__c}" label=""/></td>
                        <td><apex:outputfield value="{!Treatment_Plan__c.Product_Cost9__c}" label=""/></td>
                    </tr>
                    <tr style="display: {!IF(ISBLANK(Treatment_Plan__c.Product_Code10__c), 'none', 'table-row')};">
                        <td>10</td>
                        <td><apex:inputfield value="{!Treatment_Plan__c.Product_Code10__c}" label=""/></td>
                        <td><apex:outputfield value="{!Treatment_Plan__c.Product_Quantity10__c}" label=""/></td>
                        <td><apex:outputfield value="{!Treatment_Plan__c.Product_Provider_Occupation10__c}" label=""/></td>
                        <td><apex:outputfield value="{!Treatment_Plan__c.Product_Count10__c}" label=""/></td>
                        <td><apex:outputfield value="{!Treatment_Plan__c.Product_Cost10__c}" label=""/></td>
                    </tr>
            </table>
        </apex:pageBlock>
        <apex:pageBlock title="Sub Totals" mode="edit">       
                <table id="tfhover" class="tftable1" border="1">
                      <tr>
                            <th>Subtotal</th>
                      </tr>
                      <tr>
                            <td><apex:outputfield value="{!Treatment_Plan__c.Sub_Total_OCF18__c}" label=""/></td>
                      </tr>
                      <tr>
                            <th>HST</th>
                      </tr>
                      <tr>
                            <td><apex:outputfield value="{!Treatment_Plan__c.Total_HST_OCF18__c}" label=""/></td>
                      </tr>
                      <tr>
                            <th>Total</th>
                      </tr>
                      <tr>
                            <td><apex:outputfield value="{!Treatment_Plan__c.Total_Cost_OCF18__c}" label=""/></td>
                      </tr>
                </table>
        </apex:pageBlock>
        <apex:pageBlock title="Send OCF" mode="edit">       
                <table id="tfhover" class="tftable2" border="1">
                     <tr>
                     <th>Send OCF</th>
                     </tr>
                      <tr>
            <td><apex:inputfield value="{!Treatment_Plan__c.Send_OCF18__c}" label=""/></td>
            </tr>
            <tr>
            <th>Reduce Treatment Plan by 15%</th>
            </tr>
            <tr>
            <td><apex:inputfield value="{!Treatment_Plan__c.Reduce_Treatment_Plan_by_15__c}" label=""/></td>
            </tr>
            <br></br>
            </table>
        </apex:pageBlock>
        <apex:pageBlock >  
            <apex:pageBlockButtons location="bottom">
               <apex:commandButton id="save" value="Save" action="{!save}"/>
            </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>
</apex:page>

I need to overright the custom save button to simply save the data and rerender the page and another button to save and close the page.

My only experience is with standard buttons and I dont want to enclose everything in pageblocks, does anyone know of a way I can achieve this in my controller (copy below)
 
public with sharing class BillingTreatmentPlanController {
  
    public Treatment_Plan__c billingview {get; set;}

    public BillingTreatmentPlanController(ApexPages.StandardController
                                stdController) {
       
       billingview = (Treatment_Plan__c)stdController.getRecord();
       
       if (ApexPages.currentPage().getParameters().get('treatmentPlanId') != null) {
           billingview.ID = ApexPages.currentPage().getParameters().get('treatmentPlanId');
       }
    }   
}


 
James LoghryJames Loghry

The save button by default points to the Standard Controller's save method.  The method will invoke the standard save functionality for your given Treatment_Plan__c record.

To override this, simple add a save method to your extension, which will override the SC's save method.  For instance, add the following to your BillingTreatmentPlanController class:

public PageReference save(){
    System.debug(LoggingLevel.INFO,'Hey, I made it to the save method in the extension');
    return null;
}