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

 

 

Rahul_sgRahul_sg
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.
Rahul_sgRahul_sg
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
window.parent.location.replace(newURL);
where newURl points to the Object A record we are updating
Sohit BhardwajSohit Bhardwaj

Try This(below is example for lead object) :

 

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

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

 

 

 

 

======

 

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