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
Emilee Crocker 3Emilee Crocker 3 

How to get a button to mark a checkbox as true?

I am trying to create a button to check a checkbox as true so the workflow will activate. I keep getting the error 'TRUE" is undefined. This will be for our leads to be set up as an account.
Best Answer chosen by Emilee Crocker 3
PawanKumarPawanKumar
Please try below code. Please see the change in bold.
------------------------------------------

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

sforce.connection.sessionId = "{!$Api.Session_ID}";

var E = new sforce.SObject("Lead");
E.id = '{!Lead.Id}';

// Replace below with your field.
E.To_Be_Set_Up__c=true;

// save the change
sforce.connection.update([E]);

//refresh the page
window.location.reload();

All Answers

PawanKumarPawanKumar
Hi,
Please call the below VF at custom button, Just need to change EVENT with your OBJECT
<apex:page standardController="Event">
<apex:form >
 <script src="/soap/ajax/32.0/connection.js"></script>
<script>
    sforce.connection.sessionId = "{!$Api.Session_ID}";
    
    var E = new sforce.SObject("Event");
    E.id = '{!Event.Id}';

    // update field : what is required for You
   E.Count_Completed_Activities__c = 1;
   E.Stage__c = "Call Closed"; 
   E.Closed_Call__c = new Date().toISOString();
   
   // save the change
   sforce.connection.update([E]); 
   
   //refresh the page
   window.location.reload();
</script>
</apex:form>
</apex:page>

Regards,
Pawan Kumar
Emilee Crocker 3Emilee Crocker 3
I used your response but the button still comes up with a Syntax error. I have it set to execute Java Script onclick. This is what I am using:
<apex:page standardController="Event">
<apex:form >
 <script src="/soap/ajax/32.0/connection.js"></script>
<script>
    sforce.connection.sessionId = "{!$Api.Session_ID}";
   
    var E = new sforce.SObject("Event");
    E.id = '{!Event.Id}';

    // update field : what is required for You
   E.Count_Completed_Activities__c = 1;
   E.Stage__c = "Call Closed";
   E.Closed_Call__c = new Date().toISOString();
  
   // save the change
   sforce.connection.update([E]);
  
   //refresh the page
   window.location.reload();
</script>
</apex:form>
</apex:page>
 
PawanKumarPawanKumar
Hi Emille,

If you are using java script button the use below code.

--------------------------------------------------------------------------------
{!REQUIRESCRIPT("/soap/ajax/33.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/33.0/apex.js")}

sforce.connection.sessionId = "{!$Api.Session_ID}";

var E = new sforce.SObject("Event");
E.id = '{!Event.Id}';

// Replace below with your field.
E.Count_Completed_Activities__c = 1;

// save the change
sforce.connection.update([E]);

//refresh the page
window.location.reload();




------------------------------------------------------------------------------------------------

If still any error, please share me your object API Name  and Feld Api Name what you are trying to update. I will sahre you proper code.

Regards,
Pawan Kumar
PawanKumarPawanKumar
Hi Emilee,
Please share your code.

Regards,
Pawan Kumar
Emilee Crocker 3Emilee Crocker 3
This is what I have but I am still getting True is undefined error.
{!REQUIRESCRIPT("/soap/ajax/33.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/33.0/apex.js")}

sforce.connection.sessionId = "{!$Api.Session_ID}";

var E = new sforce.SObject("Lead");
E.id = '{!Lead.Id}';

// Replace below with your field.
{!Lead.To_Be_Set_Up__c}=TRUE;

// save the change
sforce.connection.update([E]);

//refresh the page
window.location.reload();
PawanKumarPawanKumar
Please try below code. Please see the change in bold.
------------------------------------------

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

sforce.connection.sessionId = "{!$Api.Session_ID}";

var E = new sforce.SObject("Lead");
E.id = '{!Lead.Id}';

// Replace below with your field.
E.To_Be_Set_Up__c=true;

// save the change
sforce.connection.update([E]);

//refresh the page
window.location.reload();
This was selected as the best answer
Emilee Crocker 3Emilee Crocker 3
Thank you! With that change it worked