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
SFDHSFDH 

Apex controller for custome lead Convert Visualforce page

hi ..

 

 I have Build a Vf page for Lead Convertion , but stuck with Controller please help me to finish this to convert the lead as the builtin Lead Convert Process but it should also create contact with it ... Cheak my Vf Code below

 

Please Correct the Visualforce page also , if any mistakes are there .....

 

My VF :

 

<apex:page standardController="lead" tabStyle="Lead" extensions="leadconvertController" >
<apex:messages />
<apex:sectionHeader title="Convert Lead"/>

<apex:form id="frm1">
<apex:pageBlock mode="edit" id="pgBlock">

<apex:pageBlockSection title="Contacts" columns="1" id="pgBlockSection">
<apex:pageBlockSectionItem id="pgBlockSectionitem">
<apex:outputText value="Create contacts now ?" />
<apex:selectRadio id="idRadio1" onclick="boolFunction(this);" >
<apex:selectOption itemValue="true" itemLabel="Yes" />
<apex:selectOption itemValue="false" itemLabel="No" />
</apex:selectRadio>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>

<span id="idSpan" style = "display:none">
<apex:pageBlock >
<apex:pageBlockSection title="Details" columns="1" id="Details">
<apex:outputLabel > <apex:pageBlock id="trainersBlock">
<apex:outputText value="Select for New ? " />
<apex:inputCheckbox id="isEmp" value="{!isChecked}" >
<apex:actionsupport event="onclick" rerender="SampleView" />
</apex:inputCheckbox>
<br></br>
<apex:outputPanel id="SampleView"><br></br>
<apex:pageBlockSection rendered="{!isChecked}">

<apex:pageBlockSectionItem id="pbsi1">
<apex:outputLabel value="First Name" for="Firstname" />
<apex:inputText id="Firstname" value="{!FirstName}" size="40"/>
</apex:pageBlockSectionItem>


<apex:pageBlockSectionItem id="pbsi2" >
<apex:outputLabel value="Last Name" for="Lastname"/>
<apex:inputText id="Lastname" value="{!LastName}" size="40"/>
</apex:pageBlockSectionItem>

 

<apex:pageBlockSectionItem >
<apex:outputLabel value="Phone" for="Phone"/>
<apex:inputText value="{!Phone}" id="Phone"></apex:inputText>
</apex:pageBlockSectionItem>



<apex:pageBlockSectionItem >
<apex:outputLabel value="Mobile" for="MobilePhone" />
<apex:inputText value="{!Mobile}" id="MobilePhone"></apex:inputText>
</apex:pageBlockSectionItem>


<apex:pageBlockSectionItem >
<apex:outputLabel value="Title" for="Title"/>
<apex:inputText value="{!Title}" id="Title"></apex:inputText>
</apex:pageBlockSectionItem>

<apex:pageBlockSectionItem >
<apex:outputLabel value="Email" for="Email"/>
<apex:inputText value="{!Email}" id="Email"></apex:inputText>
</apex:pageBlockSectionItem>

<apex:pageBlockSectionItem >
<apex:outputLabel value="Website" for="Website"/>
<apex:inputText value="{!Website}" id="Website"></apex:inputText>
</apex:pageBlockSectionItem>

<apex:pageBlockSection >
<apex:inputField value="{!lwn.ReportsToId}"/>
<apex:outputLabel />
</apex:pageBlockSection>

</apex:pageBlockSection>
<br></br>
<apex:pageBlockSection rendered="{!IF(isChecked = true , false , true)}">


<apex:pageBlockSectionItem id="pbsi" >
<apex:outputLabel value="Existing contact Name" for="contactName"/>
<apex:selectList id="contactname" value="{!contactName}" size="1" multiselect="false">
<apex:selectoptions value="{!ContactList}" />
</apex:selectList>
</apex:pageBlockSectionItem>



</apex:pageBlockSection>
</apex:outputPanel>

</apex:pageBlock> </apex:outputLabel>
</apex:pageBlockSection>
</apex:pageBlock>
</span>

</apex:form>

<script>

function boolFunction(variable)
{
var bool = variable.value;
if(bool == 'true')
{
document.getElementById('idSpan').style.display = 'block';
}
else
document.getElementById('idSpan').style.display = 'none';
}
</script>

<apex:form >
<apex:pageBlock mode="Edit">
<apex:pagemessages />

<apex:pageBlockSection title="Convert Lead" columns="1">
<apex:pageBlockSectionItem >
<apex:outputLabel value=" Record Owner" for="Record Owner"/>
<apex:inputField value="{!Lead.OwnerID}"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:OutputLabel for="Send Email to the Owner">Send Email to the Owner:</apex:OutputLabel>
<apex:inputCheckbox onclick="{!Lead.Ownerid}"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel for="Last Name">Last Name</apex:outputLabel>
<apex:inputField id="Name" value="{!Lead.LastName}" />
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel for="Account Name">Account Name</apex:outputLabel>
<apex:inputField required="true" id="Owner" value="{!Lead.Company}" />
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel for="Oppt Name">Opportunity Name:</apex:outputLabel>
<apex:inputField required="true" id="Owner" value="{!Lead.Company}" />
</apex:pageBlockSectionItem>
<apex:pageblockSectionItem >
<apex:outputLabel for="no oppty">Do not create new opportunity upon conversion</apex:outputLabel>
<apex:inputCheckbox required="true" onselect="{!lead.Company}"/>
</apex:pageblockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel for="ConStatus">Converted Status:</apex:outputLabel>
<apex:inputField id="ConStatus" value="{!Lead.Status}" />
</apex:pageBlockSectionItem>
</apex:pageBlockSection>






<apex:pageBlockSection title="Address Information" columns="1" id="AddressInformation">
<apex:pageBlockSectionItem >
<apex:outputLabel for="StreetAdd">Street Address:</apex:outputLabel>
<apex:inputField required="true" Id="StreetAdd" Value="{!Lead.Street}" />
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel for="City">City:</apex:outputLabel>
<apex:inputField required="true" Id="City" Value="{!Lead.City}" />
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel for="State">State:</apex:outputLabel>
<apex:inputField required="true" Id="State" Value="{!Lead.State}" />
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel for="Zip">Postal Code:</apex:outputLabel>
<apex:inputField required="true" Id="Zip" Value="{!Lead.PostalCode}" />
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
<apex:pageBlockSection title="Additional Information" columns="2" id="AdditionalInformation">
<apex:pageBlockSectionItem >
<apex:outputLabel for="NoofEmp">No. Of Employees:</apex:outputLabel>
<apex:inputField Id="Owner" Value="{!Lead.NumberOfEmployees}" />
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel for="Revenue">Annual Revenue:</apex:outputLabel>
<apex:inputField Id="Revenue" Value="{!Lead.AnnualRevenue}" />
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel for="Industry">Industry:</apex:outputLabel>
<apex:inputField Id="Industry" Value="{!Lead.Industry}" />
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel for="Description">Description:</apex:outputLabel>
<apex:inputField Id="Description" Value="{!Lead.Description}" />
</apex:pageBlockSectionItem>
<apex:pageblockSectionItem >
<apex:outputLabel for="Phone">Phone</apex:outputLabel>
<apex:inputField required="true" id="Phone" value="{!Lead.Phone}"/>
</apex:pageblockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel for="Email">Email</apex:outputLabel>
<apex:inputField required="true" id="Email" value="{!Lead.Email}"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel for="Website">Website:</apex:outputLabel>
<apex:inputField Id="Website" Value="{!Lead.Website}" />
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
<apex:pageBlockSection title="Task Information" columns="2" id="TaskInformation">
<apex:pageBlockSectionItem >
<apex:outputLabel for="Status">Status</apex:outputLabel>
<apex:inputField value="{!Task.Status}"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel for="DueDate">Due Date</apex:outputLabel>
<apex:inputField value="{!Task.ActivityDate}"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel for="Priority">Priority</apex:outputLabel>
<apex:inputField value="{!Task.Priority}"/>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
<apex:pageBlockSection title="Description Information" columns="1" id="DescriptionInformation">
<apex:pageBlockSectionItem >
<apex:outputLabel for="Subject">Subject</apex:outputLabel>
<apex:inputField required="true" value="{!Task.Subject}"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel for="Comments">Comments</apex:outputLabel>
<apex:inputField value="{!Task.Description}"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:OutputLabel for="Send Notification Email">Send Notification Email</apex:OutputLabel>
<apex:inputCheckbox onclick=""/>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
<apex:pageBlockSection title="Reminder" columns="1" id="Reminder">
<apex:pageBlockSectionItem >
<apex:outputLabel for="Reminder">Reminder</apex:outputLabel>
<apex:inputField id="Reminder" value="{!task.ReminderDateTime}"/>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
<apex:pageBlockButtons >
<apex:commandButton value="Convert"/>
<apex:commandButton Action="{!Cancel}" value="Cancel"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>

 

 

Controller :

 

public class leadconvertController {

 

Lead lead;
Opportunity opty;
Id optt;
Account account;
Contact contact;

public Boolean isChecked { get; set; }

public String contactName{get;set;}

public String leadName{get;set;}
public String FirstName {get; set;}
public String LastName {get; set;}
public contact lwn {get; set;}
public String Description{get;set;}

public String leadSource{get;set;}
public String leadIndustryName{get;set;}
public String leadstatus{get;set;}
public string Mobile{get;set;}
public string Phone{get;set;}
public string email{get;set;}
public string Website{get;set;}
public string leadrating{get;set;}
public string Title{get;set;}
Public String Street{get;Set;}
Public String City{get;Set;}
Public String State{get;Set;}
Public String PostalCode{get;Set;}
Public String Country{get;Set;}

public List<SelectOption> getContactList() {
Contact[] Contacts = [SELECT Id,Firstname,Lastname,name,reportstoid FROM Contact];
List<SelectOption> options = new List<SelectOption>();
options.add(new SelectOption('- None Selected - ','- None Selected - '));
for (Contact acc : Contacts) {
options.add(new SelectOption(acc.Name,acc.Name));
}
return options;}

public Task getTask(){
Task tsk = new Task();
return tsk;
}

public List<SelectOption> getStatus()
{
List<SelectOption> options = new List<SelectOption>();

Schema.DescribeFieldResult fieldResult = Schema.sObjectType.Lead.fields.status;
//Lead.LeadSource.getDescribe();

List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();

for( Schema.PicklistEntry f : ple)
{
options.add(new SelectOption(f.getLabel(), f.getValue()));
}
return options;
}

public List<SelectOption> getLeadIndustryNames()
{
List<SelectOption> options = new List<SelectOption>();

Schema.DescribeFieldResult fieldResult = Schema.sObjectType.Lead.fields.Industry;
//Lead.LeadSource.getDescribe();

List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();

for( Schema.PicklistEntry f : ple)
{
options.add(new SelectOption(f.getLabel(), f.getValue()));
}
return options;
}

public List<SelectOption> getPriority()
{
List<SelectOption> options = new List<SelectOption>();

Schema.DescribeFieldResult fieldResult = Schema.sObjectType.Account.fields.CustomerPriority__c;
//Lead.LeadSource.getDescribe();

List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();

for( Schema.PicklistEntry f : ple)
{
options.add(new SelectOption(f.getLabel(), f.getValue()));
}
return options;
}

public leadconvertController(ApexPages.StandardController controller) {

}


}

 

 

please provide the code for this ....

 

 

sambasamba

Can you send sandbox's username and password to my email. I will check it when i have some time.

 

Thanks,

Samba