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

Pass Value from Case to Lead

This one seems to be getting the best of me. I'm trying to pass a value from Case to this Lead form. I've been trying two ways: URL and Controller Extension.

I created a button 'Create Lead' in the Case page layout. trying to pass value with Phone. What am I doing wrong here....

Button URL:
var myURL = '{!Case.Id}&{!Lead.Phone}={!Case.Phone}';

Lead_Override_test Page:
<apex:page standardController="Lead" extensions="caseToLeadExtension" action="{!setCaseInfo}" sidebar="false" showHeader="false">
    <apex:form >
        <apex:sectionHeader title="Lead Edit" subtitle="">
        <apex:pageBlock mode="edit" id="lead" title="Lead Edit">      
            <apex:pageblockbuttons >
             <apex:commandbutton action="{!save}" value="Save"></apex:commandbutton>
             <apex:commandbutton action="{!cancel}" value="Cancel"></apex:commandbutton>
                <apex:pageblocksection title="Lead Information">
                 <!-- Make Owner field editable -->
                 <apex:inputfield value="{!Lead.OwnerId}" id="ownerid"></apex:inputfield>
                 <!-- Start Default User -->
                <script type="text/javascript">
                    document.getElementById('{!$Component.ownerid}').value = '{!$User.FirstName} {!$User.LastName}';
                <!-- END Default User -->
                 <apex:pageblocksectionitem >
                 <apex:outputlabel value="{!$ObjectType.Lead.Fields.FirstName.label}"></apex:outputlabel>
                 <apex:outputpanel >
                 <apex:inputfield value="{!Lead.Salutation}"></apex:inputfield>
                 <apex:inputfield value="{!Lead.FirstName}"></apex:inputfield>
                 <apex:inputfield value="{!Lead.Phone}"></apex:inputfield>
                 <apex:inputfield value="{!Lead.LastName}"></apex:inputfield>

Please help, Thanks!
forgot Controller:

public class caseToLeadExtension{
private final id caseId;
private final id leadId;

public caseToLeadExtension(ApexPages.StandardController con){

public void setCaseInfo(){
// in case we're missing either id
if(caseId==null || leadId==null)
Case theCase=[SELECT id,,name__c,Contact_Number__c
from Case
WHERE id=:caseId];
Lead theLead=[SELECT id,Name,Company
from Lead
WHERE id=:leadId];
// preset any Lead field you like
theLead.Company = theCase.Contact_Number__c;
theLead.Home_Phone__c = theCase.name__c;
// ....
// ....

insert theLead;

Please check this post and see if there is something you are missing. This post answers a similar requirement