How To: Improve Your Lead Conversion Data Validation

It can sometimes be tough to get the balance of data validation just right on the lead object in Salesforce. By its very nature it’s a temporary, transient object designed for pre-qualifying a contact, organisation or enquiry, and many of them never go anywhere – so you don’t want to be too heavy-handed with validation rules. But for the ones that do go somewhere and get converted, it’s important that the account, contact and opportunity they create have a good start in life, with reliable, full data – so you may be tempted to load up on validation rules to ensure you get all the right information.

Many organisations settle somewhere in the middle: they have a few select validation rules to protect critical data (Phone Number and Email Address for example) but only enforce these at the point of conversion by using the IsConverted value in their rule’s formula.

That can work very well in terms of data cleanliness, but you might find it harms your user experience somewhat, since the error will only fire on the lead conversion screen, by which point the user may well have already found a matching account, renamed the opportunity and created a follow-up task, only to be told that they can’t convert the lead since it has critical values missing. Users don’t like seeing errors at the best of times, but to see it like this and then have to go back, edit the lead and re-try the conversion – that’s not at all cool!

Validation Rule Error

So what’s the answer? Is there a way we can enforce data validation checks at the point of conversion but maintain a better user experience? Of course there is!

You just need to use a little bit of JavaScript and some custom button magic…

Start by navigating to Setup > Customize > Leads > Buttons, Links and Actions, and click New Button or Link. Give your button a label (just using Convert will probably be the most seamless user experience) and a name, then choose ‘Detail Page Button’ and ‘Execute JavaScript’.

Button Options

The JavaScript code you need to enter in the main body of the button definition will depend on your specific requirements, but say you wanted to check that every lead has a Phone and an Email value before it can be converted, you’d use the following:

var email = '{!JSENCODE(Lead.Email)}'; 
var phone = '{!JSENCODE(Lead.Phone)}';
if (email == '' || phone == '' ){ 
alert('Woah there! Please ensure the Phone and Email are completed in before you convert.'); 

You can replace the alert message with any text of your choice. Now just add the button to your page layout (and remember to remove the standard Convert button).

Then, when your users click Convert they’ll either see a more user-friendly alert letting them know what they need to do, or they’ll be redirected to the standard convert screen as usual – safe in the knowledge that they won’t later be tripped up by the validation rule!



Shout out to Mike Gill whose JavaScript knowledge is far superior to mine and who helped me refine this solution the first time round. I’ve since used it multiple times in many orgs and now I couldn’t live without it – I hope you like it too!

Leave a Reply

%d bloggers like this: