I am currently working on a button on the lead object to automatically select a check box field on the lead object when pushed. The field is called "advocate_record_created__C". When trying to execute the command via the button I get an error message "ILLEGAL". My JavaScript experience is limited, but here is the code I tried:


//If the lead advocate check box is not checked, update field to checked. 

IF({!Lead.Advocate_Record_Created__c} == false) 

var L = new sforce.SObject("Lead"); 
L.id = {!Lead.Id}; 
L.Advocate_Record_Created__C = true; 
result = sforce.connection.update([L]); 

//If Field update was successful, success! Reload page. 


//If the field is already selected, error message. 

alert("already True"); 

Any insight as to why this is not executing correctly is greatly appreciated. My experience with JavaScript is very limited. Thanks!


I Updated the code and now the button works. The code I used is as follows:

var newRecords = []; 
var L = new sforce.SObject("Lead"); 
L.id ="{!Lead.Id}"; 
L.Advocate_Record_Created__c = true; 
result = sforce.connection.update(newRecords); 
| improve this answer | |

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.