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
Itayb34Itayb34 

Custom Button Using Javascript

Hello

 

I have a general question regard Javascript in custom button. I want that the user will get an error message if a field is blank on the lead layout (in this case - company type).

The code below is working, just wanted to understand if "REQUIRESCRIPT" section is needed (connection and apex rows)

 

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

var leadObj = new sforce.SObject("Lead"); 
leadObj.Id = '{!Lead.Id}'; 
var type = "{!Lead.Company_Type__c}"; 
if (type == "") 
{ 
alert("Please enter company type before converting this lead"); 
} 

else{ 
var result = sforce.connection.update([leadObj]); 
window.location.href = "/lead/leadconvert.jsp?retURL=%2F{!Lead.Id}&id={!Lead.Id}"; 
}

 

Thanks!

 

Itay

Cloud CredenceCloud Credence

Hi Italy,

 

Yes the Requirescripts are necessary.

 

The sforce object that you have used in the code is not available in javascript. This is available through these included libraries.

 

Thanks