+ Start a Discussion
XVLXVL 

I am trying to create a work flow on a lead that will alert an owner when the lead has been in "Working" status for more than 14 days.

I am trying to create a work flow on a lead that will alert an owner when the lead has been in "Working" status for more than 14 days. At this point, the system should create a task. I have created a date field that tracks the date. I have tried using a formula to count the number of days and set the workflow criteria o 14. That  did not work. I have also tried using a custom field that updates with todays date when the lead is changed to working. But, nothing seemes to work. I know about time based workflows, but I can't "build" on my previous worklow, but doing that prevents the lead from being able to be converted. 
Best Answer chosen by XVL
XVLXVL
Thank you for your response. I tried this previously but had huge issues. My org has hundreds of leads that come in daily and it's not scalable to have every user contact me so that I manually clear the time based work flow so that they can continue their sales process. I found something that seems to work.

I found a solution that seems to work quite well in my test. 

http://www.opfocus.com/blog/how-to-convert-a-lead-in-use-by-a-time-based-workflow-in-salesforce/

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:


<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>

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.

All Answers

Vinita_SFDCVinita_SFDC
Hi,

You can achieve this with time based workflow only. You can deactivate previous WF and create new time based wf. Regarding preventing leads from being converted, can you check debug logs for what error do you get on converting lead.

Refer: https://help.salesforce.com/HTViewSolution?id=000005245&language=en_US
XVLXVL
Thank you for your response. I tried this previously but had huge issues. My org has hundreds of leads that come in daily and it's not scalable to have every user contact me so that I manually clear the time based work flow so that they can continue their sales process. I found something that seems to work.

I found a solution that seems to work quite well in my test. 

http://www.opfocus.com/blog/how-to-convert-a-lead-in-use-by-a-time-based-workflow-in-salesforce/

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:


<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>

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.
This was selected as the best answer
TAPSFDCYYCTAPSFDCYYC
Thanks XVL, the solution works great to stop the workflow rules prior to convert.  There is one gap in the solution that I hope you (or anyone else) can answer.  When the user is on the Convert page then presses cancel, rather than save, the Checkbox remains Checked on the Lead record and now all workflow rules won't reevaluate.  Can someone dream up a solution utilizing the above VFP Code?

Thanks in advance!

Cheers
Trevor
Eric Boller 14Eric Boller 14
When I try using the above VisualForce page I am just directed to a blank page and nothing happens. Why would this be?