function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Jag SinghJag Singh 

Lead Conversion with Time-dependent Workflow through VF Page

Hi,

I was wondering if someone could kindly help with my code to convert a Lead when it has a time based workflow running against it.

1. Firslty, I worked from this blog in how to do it:

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

2. I'm not great with coding so wanted some guidance of why I'm getting the following error message when creating a VF page:

Invalid parameter for function URLFOR
Error is in expression '{!URLFOR($Action.Lead.Convert, lead.id, [retURL=$CurrentPage.parameters.retURL], true)}' in page leadconversion


3. Code is as follows:

<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. My VF page URL is: https://c.cs18.visual.force.com/apex/LeadConversion


Any kind of help here would be amazing as this would be very beneficial for our company.

Thanks in advance,
Jag
Sumitkumar_ShingaviSumitkumar_Shingavi
Try using something like http://blog.jeffdouglas.com/2009/02/13/enhancing-the-lead-convert-process-in-salesforce/

rather than way you using it.

PS: if this answers your question then hit Like and mark it as solution!
Jag SinghJag Singh
Hi SumitKumar,

I'm not sure how this would help me? Any guidance?

Thanks,
J
Sumitkumar_ShingaviSumitkumar_Shingavi
Ok, more simpler way than what I am saying below:

Implement a method in a class like below
public class ConverLeadCC {
	
	public Lead myLead {get; set;}
	
	public myControllerExtension(ApexPages.StandardController stdController) {
            this.myLead = new Lead();
            this.myLead = (Lead) stdController.getRecord();
        }
	
	public statice PageReference converLead() {
		
	        if(myLead != null && myLead.Id != null) {
			Database.LeadConvert lc = new Database.LeadConvert();
			lc.setLeadId(myLead.Id);
			lc.setOpportunityName(myLead.Name);
			lc.setAccountId(accountMap.get(myLead.Company).id);
			LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
			lc.setConvertedStatus(convertStatus.MasterLabel);
			Database.LeadConvertResult lcr = Database.convertLead(lc);
		
			return new PageReference('/' + [SELECT Id, ConvertedOpportunityId FROM Lead WHERE Id =: myLead.Id LIMIT 1].ConvertedOpportunityId);
		}
	}	
}
Associate this controller as controller with your VF page and in <apex:page> tag there is property called "action" which you can set like below:
<apex:page standardController="Lead" extensions="ConverLeadCX" action="converLead">
Make sure your URL of Page should have "Id" of Lead like /apex/myVFPage?id=xxxxxxxx

PS: if this answers your question then hit Like and mark it as solution!