How to Convert a Lead In Use By a Time-Based Workflow in Salesforce
Have you ever tried to convert a Lead, only to get the “Unable to convert lead that is in use by workflow” message? Frustrating, isn’t it?
This message appears if the Lead you want to convert is waiting on the Time-Based Workflow queue, waiting for some event to occur. Salesforce prevents you from converting these Leads until they are removed from the queue. Your options are few:
- Tell your user to edit the Lead to change whatever value(s) caused the record to be placed on the queue. This should cause the Lead to be removed from the workflow queue, so the user can try again to delete it. Of course, that’s a lot of work to ask your users to do, just to convert a Lead.
- Tell your users to let you know when they get this message. You can go to the queue (Setup | Monitoring | Time-Based Workflow, find the record on the queue, and delete it. Then tell the user to try again. But do you really want to do that every time a user wants to convert a Lead that’s on the queue?
What you really need is an approach that can be automated so you or your users don’t have perform extra steps, and that doesn’t involve Apex. Wouldn’t it be great if you could just override the standard Convert button?
The solution involves overriding the standard Convert button, so that it sends the user to a Visualforce page instead. The page, which will be displayed for only a second or less, will check a new checkbox field on your Lead, then redirect to the standard Lead Convert page. If you change your workflow rule’s criteria to exclude any Leads that have this new checkbox checked, then by the time the standard Lead Convert page is displayed, the Lead will no longer be on the workflow queue, and you’ll be able to convert it without any problem.
Here’s what you need to do:
1. Add a new checkbox field
Create a checkbox field named Cancel Workflow to the Lead object. By default, the checkbox is unchecked. The field doesn’t need to appear on the page layout.
2. Edit Your Workflow Rule
Change your workflow rule to add “Cancel Workflow equals False” to the criteria. In other words, if the new checkbox becomes checked, the Lead will no longer meet the workflow criteria.
3. Create a Visualforce page like this:
4. Override Lead Object’s Standard Convert Action
Override the Lead object’s standard Convert action with the new Visualforce page. (Use Setup | Customize | Leads | Buttons and Links, then click Edit next to the Convert link to get to the override page.)
With this in place, when you click the Lead’s Convert button, you’ll see a brief flicker as this page is loaded and does its work, but the page will then redirect to the standard Lead Convert page. By the time you get there, the Lead will have been removed from the workflow queue, and you’ll be free to convert the Lead.
Try it, and let us know how it works for you!
Something to Consider
There’s only one issue with this solution. If you decide not to Convert the Lead and instead click Cancel on the Convert page, the Lead will remain unconverted, but its Cancel Workflow field will remain checked, preventing the Lead from being placed on the time-based workflow queue. You could develop a Scheduled Apex process to detect unconverted Leads whose Cancel Workflow field is checked, and then uncheck them, but that involves developing Apex, which we’ve otherwise avoided in this solution. If you’ve got any ideas, please post them here!
Photo credit: Simon_sees
Meet the OpFocus Team at Dreamforce 2011 This Summer
That’s right! The OpFocus team will be at Dreamforce to soak in all the information that Salesforce.com has to offer and meet with old and new friends alike. If you are a customer, a friend or a fan of OpFocus, please let us know if you will be attending Dreamforce. We would love to see you there!