0

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:

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


//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(results[0].getBoolean("success")) 
{ 
window.location.reload(); 
} 

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

ELSE { 
alert("already True"); 
}}

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

0

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

{!REQUIRESCRIPT("/soap/ajax/22.0/connection.js")} 
var newRecords = []; 
var L = new sforce.SObject("Lead"); 
L.id ="{!Lead.Id}"; 
L.Advocate_Record_Created__c = true; 
newRecords.push(L); 
result = sforce.connection.update(newRecords); 
window.location.reload();

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.