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
Mayank Srivastava (Salesforce fan)Mayank Srivastava (Salesforce fan) 

How to check a custom checkbox field when certain conditions are met?


I'm trying to write a one line OnClick Javascript code for unchecking a custom checkbox field when certain conditions are met. Can anyone please help me write it?


Name of checkbox custom field: "Active"


Here's the pseuodocode:


Set "Active"(checkbox)= False

where Account= X 

and Installation = QA



why are you writing javascript for this? is it a VF page. If yes you should use partial page refresh and controller function.
Mayank Srivastava (Salesforce fan)Mayank Srivastava (Salesforce fan)
Rahul, This is what I'm trying to accomplish. I have a custom object called A which has a custom button. When I click this custom button, a new record is created into another custom object called B using data from A. I want to uncheck a custom checkbox on object A after this record has been created. No it's not a visualforce page.
ok got it , so you should be calling an apex class from that button using sforce.apex.execute.
In the same class you may update the object A by setting that boolean flag.

and then refresh the page using
where newURl points to the Object A record we are updating
Sohit BhardwajSohit Bhardwaj

Try This(below is example for lead object) :



var newRecords = [];
var c = new sforce.SObject("Lead"); ="{!Lead.Id}";
c.CheckByButton__c= true;
result = sforce.connection.update(newRecords);







replace c.CheckByButton__c with the field name that exist on the object