I would like to prevent users from converting a lead if some fields are missing (State, country, company type) - I don't want to use standard validation, as I want the users to remain on the same screen and add details if needed. I added the code below for the custom button. Do I need to add anything to it?

var state = "{!Lead.State}";
var country = "{!Lead.Country}";
var type = "{!Lead.Company_Type__c}";
if (state == '' || country == '' || type == '') 
alert('missing fields, please complete'); 
window.location = 'https://cs9.salesforce.com/lead/leadconvert.jsp?retURL=%2F{!Lead.Id}&id={!Lead.Id}'; 

  • Can you clarify? Does the button perform as desired? Right now this is looking more as a JavaScript validation question and not much of a Salesforce question and is in danger of being closed.
    – Mike Chale
    Commented May 2, 2013 at 11:27

1 Answer 1


Your code is clean. Only one thing: use relative URL instead of absolute, so you dont need to adjust the link to the current org after deployment:


  • Thanks @sergey, just one minor question...why I don't have to add the following "!REQUIRESCRIPT("/soap/ajax/19.0/connection.js")}" to the code? I saw this in several examples (maybe it's for creation / update records?)
    – Itay B
    Commented May 2, 2013 at 8:40
  • @ItayB This is an Salesforce AJAX Toolkit typographical convention. It will be used (like you said) for the CRUD operations. You can read the docs here: salesforce.com/us/developer/docs/ajax/… Commented May 2, 2013 at 8:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .