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
JaanuJaanu 

Updating check box based on click of custom button ?

I have added a custom button in custom object (Cust__c) page layout. on click of button, I want to update the check box, which is not working. I have the following code in custom button javascript logic... pls help/

Check__c - Check box field
CheckPE__c - Check box field
Code is below

if(Check__c = true){ 
    CheckPE__c = true; 
    alert('Successfull!')
}
else{
    alert("validate");
}
Raj VakatiRaj Vakati
Give me complete code
JaanuJaanu
This is the compete code I have ? I just have to check one field and update another field based on the first field. Can you pls give me complete code which will work..thanks.
JaanuJaanu
any help pls
Raj VakatiRaj Vakati
try like below
 
{!REQUIRESCRIPT("/soap/ajax/43.0/connection.js")} 

var LeadToUpdate = new sforce.SObject("Lead"); 
if (LeadToUpdate.Check__c ==true) { 
LeadToUpdate.Id = "{!Lead.Id}"; 
LeadToUpdate.CheckPE__c  =false; 
else { 
alert( result[0].errors.message ); 

}

 
Ajay K DubediAjay K Dubedi
Hi Jaanu,

Below code can fulfill your requirements. Hope this will work for you.

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

     if({!Account.Check__c} == false)
     {
          var c = new sforce.SObject("Account");
          c.id = "{!Account.Id}";
          c.Check__c = true;
          c.CheckPE__c  =false; 
          result = sforce.connection.update([c]);
          if ( result[0].getBoolean( "success" ) )
          {
               window.location.reload();
          }
          else
          {
               alert( result[0].errors.message);
          }
     }
     else
     {
          alert("Already True");
     }
     
Please mark this as best answer if this solves your problem.

Thank you
Ajay Dubedi