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

Overwrite SAVE button on Opportunity Edit Page?

Hi there,

I need to place the following S-control on the SAVE button for **Opp Edit Page** so that it creates the ALERT message each time the user clicks on the SAVE button.


<script type="text/javascript" language="javascript" src="/js/functions.js"></script>
<script type="text/javascript" src="/soap/ajax/10.0/connection.js"></script>
<script type="text/javascript">
function updatethechkbox()
var cas= new sforce.SObject("Opportunity");
result = sforce.connection.create([cas]);
cas.Id = "{!Opportunity.Id}";
cas.ForAlertMsg__c = "true";
result = sforce.connection.update([cas]);


    function throwalert()

     // Begin by creating 3 variables for the criteria to be met.
    // 1st RecordType should be KBB Generic for the Opportunity
    var recordtype = "{!Opportunity.RecordType}";
    // 2nd will be the TYPE of opportunity that is created, which is the standard field.
    var thetype = "{!Opportunity.Type}";
    // 3rd will be the Opportunity Status which is also a standard field.
    var isstatus = "{!Opportunity.StageName}";
   // Another variable is defined which will hold the ALERT message as this is the better approach - inside the function.

    var msgg = "You can now create the Sales Order for this Opportunity"

   // Another variable for the hidden checkbox field on the Oppor page which will be set to TRUE first time alert is displayed
     var hide = "{!Opportunity.ForAlertMsg__c}";
     //var isChanged = false; // This will be set to TRUE when the ALERT is displayed the first time.

    // Now the IF statement for 3 criteria to be met, along with the following:-
    //  1. Check if the chkbox is set to TRUE or not.
    // 2. If checkbox is NOT TRUE then display the message and set it to TRUE.
    // 3. If checkbox is TRUE then dont display the message.

     if ((recordtype == "KBB Generic") && (thetype == "KBB KPO") && (isstatus == "Closed Won") && ({!Opportunity.ForAlertMsg__c} == false))

                     window.parent.location.replace = "{URLFOR($Action.Opportunity.View, Opportunity.Id,null,true)};"
<body onload="throwalert()";>

How can I overwrite the SAVE button on Opportunities?

You can't overwrite a save button.  Try writing an Apex trigger instead.  Based on your code below it seems like you can do all that in an Apex trigger.