2

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'); 
} 
else 
{ 
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 May 2 '13 at 11:27
2

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:

https://cs9.salesforce.com/lead/leadconvert.jsp?retURL=%2F{!Lead.Id}&id={!Lead.Id}

  • 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 May 2 '13 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/… – Sergej Utko May 2 '13 at 8:50

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.