+ Start a Discussion
jcaldjcald 

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 = 'https://cs18.salesforce.com/apex/Lead_Override_test?caseId=={!Case.Id}&{!Lead.Phone}={!Case.Phone}';
srcUp(myURL);


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:sectionHeader>
        <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:pageblockbuttons>
                <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}';
                </script>
                <!-- 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:outputpanel>
                 </apex:pageblocksectionitem>               
                 <apex:inputfield value="{!Lead.Phone}"></apex:inputfield>
                 <apex:inputfield value="{!Lead.LastName}"></apex:inputfield>
                 .......etc
        </apex:pageBlock>
    </apex:form>
</apex:page>


Please help, Thanks!
jcaldjcald
forgot Controller:

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

public caseToLeadExtension(ApexPages.StandardController con){
this.leadId=con.getId();
this.caseId=ApexPages.currentPage().getParameters().get(caseId);
}



public void setCaseInfo(){
// in case we're missing either id
if(caseId==null || leadId==null)
return;
Case theCase=[SELECT id,Contact.name,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;
}

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

https://success.salesforce.com/answers?id=90630000000gwhCAAQ