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:
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?
You can!
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:
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.
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.
<apex:page standardController="Lead" >
<apex:form>
<div style="visibility:hidden;">
<apex:inputField value="{!Lead.Cancel_Workflow__c}" id="cancelWorkflow" style="visibility:hidden; "/>
</div>
<apex:actionFunction name="quickSave" action="{!quickSave}" oncomplete="standardConvert();"/>
<apex:actionFunction name="standardConvert"
action="{!URLFOR($Action.Lead.Convert, lead.id, [retURL=$CurrentPage.parameters.retURL], true)}" />
<script language="JavaScript">
var previousOnload = window.onload;
window.onload = function() {
if (previousOnload) previousOnload();
fixLead();
}
function fixLead() {
var elemCancelWorkflow = document.getElementById('{!$Component.cancelWorkflow}');
elemCancelWorkflow.checked = true;
quickSave();
}
</script>
</apex:form>
</apex:page>
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!
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
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!