• AmandaHowell.ax368
  • NEWBIE
  • 0 Points
  • Member since 2008

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
Hi there,

I already have a Scontrol which displays an alert message on the Opp page when the 3 criterias are met. I would like to implement the same logic in a Trigger so that it displays the alert message only when the SAVE button is clicked. Here is the code for Scontrol:-
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
<html>
<head>

<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))

     {
        updatethechkbox();
        alert(msgg);
       
       }
       else
       {          
                     window.parent.location.replace = "{URLFOR($Action.Opportunity.View, Opportunity.Id,null,true)};"
        }
     } 
    </script>
</head>
<body onload="throwalert()";>
</body>
</html>
////////////////////////////////////////////////////////////////////////////////////////

I am little confused as to how will I start writing a Trigger which does the same thing?

I understand it will be of the Before Insert and Before update.

Can you give me few starting points on this one please?

thanks