How To: Convert Leads with Pending Workflow Actions

Conversion Error

Does the above error look familiar? If not, I envy you! For those of us who have set up an awesome time-based workflow on the lead object, only to find out later that leads with pending workflow actions cannot be converted, it can be very frustrating. Here’s just one recent example from the Answers community:

Question

Sure, an admin can easily remove the lead’s pending actions from the workflow queue, but that’s a hassle for them and a waste of time for the user who just wants to get on with working on the opportunity!

Luckily for us, there is a solution. Gather round…

Step One: Create a new Checkbox field on Lead

Create a checkbox field on the lead object called something like Cancel Workflow. Default its value to false. There’s no need to add this field to any page layouts, but make sure you give edit access to any profiles that will be converting leads.

Step Two: Modify your Workflow Rule

Adapt any workflow rules on your lead which have time-based actions, by adding a criteria of Cancel Workflow equals False. This way, as soon as that field’s value changes to True, the record will be removed from the workflow queue.

Step Three: Create a Visualforce Page

This bit sounds tricky and may scare off some admins, but you can copy the code below without making any changes and you’ll have a working piece of Visualforce.

<apex:page standardController="Lead" > 
<apex:form> 
  
<apex:actionFunction name="quickSave" action="{!quickSave}" oncomplete="standardConvert();"/> <apex:actionFunction name="standardConvert" action="{!URLFOR($Action.Lead.Convert, lead.id, [retURL=$CurrentPage.parameters.retURL], true)}" /> var previousOnload = window.onload; window.onload = function() { if (previousOnload) previousOnload(); fixLead(); } function fixLead() { var elemCancelWorkflow = document.getElementById('{!$Component.cancelWorkflow}'); elemCancelWorkflow.checked = true; quickSave(); } </apex:form> </apex:page>

All this code does is to change the value of the lead’s Cancel Workflow checkbox to True and then redirect the user to the standard lead conversion screen.

Be sure to give all profiles that will be converting leads access to this Visualforce page through the Enabled Visualforce Page Access list on each profile’s detail page.

Step Four: Override the Convert Button

Now navigate to Setup > Customize > Leads > Buttons, Links and Actions. Click Edit on the Convert action and choose your new Visualforce Page from the picklist.

The Result

Now when you click Convert on a lead, you’ll be briefly diverted to the Visualforce page which will clear the lead from the queue and then immediately returned to the standard conversion page. In most cases this redirect is instant so your users may not even notice!

Bingo! You can now automatically remove leads from the workflow queue just by clicking the Convert button!

Credit to Opfocus for being the genesis of this solution. Their post came to my rescue when I first discovered the issue, and I’ve used it many times since.

2 thoughts on “How To: Convert Leads with Pending Workflow Actions

  • I just tried this and it seem like something is missing. When I do this I get a screen when clicking on convert that says:
    var previousOnload = window.onload; window.onload = function() { if (previousOnload) previousOnload(); fixLead(); } function fixLead() { var elemCancelWorkflow = document.getElementById(”); elemCancelWorkflow.checked = true; quickSave(); }

    Does this mean the apex page code is missing something?

Leave a Reply

%d bloggers like this: