0

I want to update field on click of ok in the javascript popup message. Is there any way that i can do in custom button javascript code

like we have checkbox field and when i click on ok in the message the checkbox need to be checked in the backend

thanks in advance

enter image description here

  • Adding to the answer below if you want to check whether someone has clicked "OK", you will have to use confirm() instead of alert(), something like below would work if(window.confirm("Your statement here")){} – StormBr34ker Mar 11 '17 at 15:12
2

You are going to need to create a custom button and then add a javascript to it.

Below is the sample code.Modify it as per your requirement.

{!REQUIRESCRIPT("/soap/ajax/32.0/connection.js")}

var r = confirm('Are you Sure?');
if(r == true){
     if({!Account.Checkbox__c} == false)
     {
          var c = new sforce.SObject("Account");
          c.id = "{!Account.Id}";
          c.Checkbox__c = true;
          result = sforce.connection.update([c]);
          if ( result[0].getBoolean( "success" ) )
          {
               window.location.reload();
          }
          else
          {
               alert( result[0].errors.message);
          }
     }
     else
     {
          alert("Already True");
     }
}
  • I think what OP wants is : 1) user clicks the button 2) pop up opens 3) user clicks ok in the popup 4) record updated. But your solution works this way: 1) User clicks the button 2) Record updates..See difference? – javanoob Mar 11 '17 at 15:21
  • Yes @javanoob field need to be updated after i click on the ok on popup message, that means after alert message popup then when user clicks on ok then field need to be updated – Autodidact Mar 11 '17 at 15:28
  • @josyula ,@Javanoob - I have updated my answer. – Samir Mar 12 '17 at 4:31
0

Thanks @Samir, I made little change i wrote alert message before the if condition and message is showing up when i click on the custom button, After that when i click on ok the field is updating

enter image description here

 {!REQUIRESCRIPT("/soap/ajax/32.0/connection.js")}

 alert("Successfully Submitted");

 if({!Contact.unsubscribe__c} == false)
 {
      var c = new sforce.SObject("Contact");
      c.id = "{!Contact.Id}";
      c.unsubscribe__c = true;
      result = sforce.connection.update([c]);
      if ( result[0].getBoolean( "success" ) )
      {
           window.location.reload();
      }
        else
      {
           alert( result[0].errors.message);
      }
 }
  • as per my understanding,User should get an option to click Ok or cancel.Only if the user chooses Ok, updation should occur – Samir Mar 12 '17 at 4:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.