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
Karleen MendozaKarleen Mendoza 

Add additional Lead field to customized lead conversion page

Hi all, I am completely new to Apex and such. I want to create a customize lead conversion page and would like to add an additional custom field to the lead conversion page. 

I found some sample code with a visualforce page and components already made. But I don't know how to add the additional custom field to the page?

The field name I'd like to add is "Bypass New Business Tasks", API name Bypass_New_Business_Tasks__c. It is a field on the Lead object.

This is the sample code I got:
<!-- This component allows for the core lead converting functionality -->

<apex:component controller="leadConvertCoreComponentController">
    <!-- This allows for the lookup to Account but hides the text of the selected account name leaving the magnifying glass only -->
    <style type="text/css">
        input.hiddenInput {

    <!-- This is the attribute that holds the lead to convert -->
    <apex:attribute name="LeadToConvert" 
        description="The lead to convert"

    <!-- This attribute is used for the leadConvertController to interact with this component's controller -->
    <apex:attribute name="thepageController"
      description="The controller for the page." />
    <!-- Lead Convert section -->    
    <apex:pageBlockSection id="pblockconvertLead" title="Convert Lead" collapsible="no" columns="1">
        <!-- Leads Record Owner -->
        <apex:pageBlockSectionItem >
            <apex:outputLabel value="Record Owner" for="recordOwner" />
            <apex:inputField value="{!contactId.ownerID}" id="recordOwner" />
        <!-- Checkbox indicating whether to send an email to the owner -->    
        <apex:pageBlockSectionItem >
            <apex:outputLabel value="Send Email to the Owner" for="sendOwnerEmail" />
            <apex:inputCheckbox value="{!sendOwnerEmail}" id="sendOwnerEmail" />
        <apex:pageBlockSectionItem id="convertLeadAccountBlockSectionItem" >
            <!-- Account Name picklist  -->
            <apex:outputLabel value="Account Name" for="accountList" />
            <apex:outputPanel styleClass="requiredInput" id="block">
                <div class="requiredBlock"></div>
                <apex:selectList value="{!selectedAccount}" size="1" 
                    multiselect="false" id="accountList">
                    <apex:actionSupport event="onchange" 
                        rerender="opportunityName, ViewLink"
                    <apex:selectOptions value="{!accounts}"/>
                <!--  Account lookup to add existing accounts to the picklist -->
                <apex:inputField styleClass="hiddenInput" 
                value="{!contactId.AccountId}" id="accountId" >
                    <!-- When an account is looked up, it is added to the select list -->                            
                    <apex:actionSupport event="onchange" 
                        rerender="accountList, opportunityName, ViewLink"
                <!-- This is a link which shows a view of the selected account in a new pop up window -->                
                <apex:commandLink id="ViewLink"  value="View"
                    onclick="javascript:if ('{!selectedAccount}' != 'NEW' && '{!selectedAccount}' != 'NONE' ) {var newWindow ='/{!selectedAccount}/p', 'accountview', 'top=40, left=40,scrollbars=yes, height=450, width=800');newwindow.focus();} else {alert('You can only view existing accounts.');}"
        <!-- Opportunity section -->
        <apex:pageBlockSectionItem id="oppSection" >
            <apex:outputPanel id="oppPanel" >
                <apex:outputLabel value="Opportunity Name" for="opportunityName" />
            <apex:outputPanel id="opportunityPanel" layout="block">
                <apex:outputPanel rendered="{!NOT(doNotCreateOppty)}" styleClass="requiredInput" id="block">
                <div class="requiredBlock"></div>
                <!-- Opportunity Name -->
                <apex:inputField required="false" 
                    value="{!opportunityID.Name}" id="opportunityName"/>
                <!--  This is only shown if the Do Not Create Opportunity is true -->    
                <apex:inputText disabled="true" rendered="{!doNotCreateOppty}"  value="{!opportunityID.Name}" id="opportunityNameDisabled"/>
                <apex:outputPanel layout="block" styleClass="requiredInput">
                <apex:outputPanel layout="block" />
                <!-- Checkbox indicating whether to create an Opportunity -->
                <apex:inputCheckbox value="{!doNotCreateOppty}" id="doNotCreateOppty">
                    <apex:actionSupport event="onchange" 
                Do not create a new opportunity upon conversion.
        <!-- Converted Status -->
        <apex:pageBlockSectionItem >
            <apex:outputLabel value="Converted Status" for="leadStatus" />
            <apex:outputPanel styleClass="requiredInput" layout="block">
                <div class="requiredBlock"></div>
                <apex:selectList id="LeadStatusList" size="1" 
                    value="{!LeadToConvert.Status}" multiselect="false" required="true">
                    <apex:selectOptions value="{!LeadStatusOption}"/>

<!-- This is our page component tag -->
<!-- We are using the Standard Controller for Lead and a Controller Extension called 'leadConvertController' -->

<apex:page standardController="Lead" extensions="leadConvertController">

<!-- Page section header -->

<apex:sectionHeader title="Convert Lead" subtitle="{!}"/>

<!-- Visualforce Component with custom page header text -->

<c:leadConvertPageHeaderTextComponent />

<!-- This form tag must include any fields or buttons used in the Lead Convert operation -->
<apex:form id="theForm" >

    <!-- This pageBlock component is a container that includes the visual elements of the Lead Convert page -->
    <!-- All custom Components should be included within this pageBlock unless you are using more advanced custom styling -->

    <apex:pageBlock mode="edit" id="pageBlock">
        <!-- This component is used to display error messages on the page -->
        <apex:pageMessages />
        <!-- This pageBlockButtons component is where you can add / remove custom buttons from the Lead Convert page -->
        <apex:pageBlockButtons >
            <apex:commandButton action="{!convertLead}" value="Convert"/>
            <apex:commandButton action="{!cancel}" value="Cancel"/>
        <!-- This custom component contains the section & fields specific to converting a Lead to an Account, Contact, and Opportunity -->
        <c:leadConvertCoreComponent id="leadComp" thepageController="{!this}" LeadToConvert="{!leadToConvert}" rendered="True" />

        <!-- This custom component contains the section & fields specific to creating a new Task on Lead Convert -->
        <!-- If you would like to hide this section, set the rendered attribute to 'False' -->
        <c:leadConvertTaskInfoComponent thepageController="{!this}" rendered="true" />

        <!-- This custom component contains the section & Description field specific to the new Task on Lead Convert -->
        <!-- If you would like to hide this section, set the rendered attribute to 'False' -->
        <c:leadConvertTaskDescriptionComponent thepageController="{!this}" rendered="true" />

    <!-- This is the closing tag for the pageBlock component -->
<!-- This is the closing tag for the form -->

<!-- This is the closing tag for the page -->

There are some classes and such that make the custom lead conversion page work. I just need to add the one field onto the page but I don't know where??!
Santosh Bompally 8Santosh Bompally 8
Post the apex class as well, And to which object/field you want to map Bypass_New_Business_Tasks__c to ?
Karleen MendozaKarleen Mendoza
There are quite a few Apex Classes, I'm not sure which one to post here. I downloaded these sample codes from an unmanaged package on the appexchange:

Here is one that is called "lead convert controller"
  This is the controller for the Visual Force page leadConvertPage.

public with sharing class leadConvertController extends PageControllerBase {
    // This is the lead that is to be converted
    public  Lead leadToConvert {get; set;}
    // Constructor for this controller
    public leadConvertController(ApexPages.StandardController stdController) {
        //get the ID to query for the Lead fields
        Id leadId = stdController.getId();
        leadToConvert = [SELECT Id, Status, OwnerId, Name, Company FROM Lead WHERE Id = :leadId];

  These are instances of the components' controllers which this class will access.
  If you add new custom components, add an instance of the class here
    public leadConvertCoreComponentController myComponentController { get; set; }
    public leadConvertTaskInfoComponentController myTaskComponentController { get; set; }
    public leadConvertTaskDescComponentController myDescriptionComponentController { get; set; }
      These are the set methods which override the methods in PageControllerBase. 
      These methods will be called by the ComponentControllerBase class.
      If you add new custom components, a new overridden set method must be added here.
    public override void setComponentController(ComponentControllerBase compController) {
        myComponentController = (leadConvertCoreComponentController)compController;
    public override void setTaskComponentController(ComponentControllerBase compController) {
        myTaskComponentController = (leadConvertTaskInfoComponentController)compController;
    public override void setDescriptionComponentController(ComponentControllerBase compController) {
        myDescriptionComponentController = (leadConvertTaskDescComponentController)compController;

      These are the get methods which override the methods in PageControllerBase.
      If you add new custom components, a new overridden get method must be added here.
    public override ComponentControllerBase getMyComponentController() {

        return myComponentController;


    public override ComponentControllerBase getmyTaskComponentController() {

        return myTaskComponentController;

    public override ComponentControllerBase getmyDescriptionComponentController() {

        return myDescriptionComponentController;

    // This method is called when the user clicks the Convert button on the VF Page
    public PageReference convertLead() {
    // This is the lead convert object that will convert the lead 
        Database.LeadConvert leadConvert = new database.LeadConvert();
        // if a due date is set but the subject is not, then show an error 
        if (myTaskComponentController != null && myTaskComponentController.taskID.ActivityDate != null && string.isBlank(myTaskComponentController.taskID.Subject)){
            PrintError('You must enter a Subject if a Due Date is set..');
            return null;
        // if Lead Status is not entered show an error  
        if (myComponentController != null && myComponentController.leadConvert.Status == 'NONE'){
            PrintError('Please select a Lead Status.');
            return null;
        //set lead ID
        //if the main lead convert component is not set then return
        if (myComponentController == NULL) return null;
        //if the Account is not set, then show an error
        if (myComponentController.selectedAccount == 'NONE')
            PrintError('Please select an Account.');
            return null;
        // otherwise set the account id
        else if (myComponentController != NULL && myComponentController.selectedAccount != 'NEW') {
        //set the lead convert status
        //set the variable to create or not create an opportunity
        //set the Opportunity name
            ? null : myComponentController.opportunityID.Name));
        //set the owner id
        //set whether to have a notification email
        system.debug('leadConvert --> ' + leadConvert);
        //convert the lead
        Database.LeadConvertResult leadConvertResult = Database.convertLead(leadConvert);
        // if the lead converting was a success then create a task
        if (leadConvertResult.success)
          // make sure that the task information component is being used and check to see if the user has filled out the Subject field 
            if(myTaskComponentController != NULL 
                && myDescriptionComponentController != NULL 
                && myTaskComponentController.taskID.subject != null)
              //create a new task
                Task taskToCreate = new Task();
                //set whether there is a reminder
                taskToCreate.IsReminderSet = myTaskComponentController.remCon.taskID.IsReminderSet;
                //if the reminder is set, and the reminder's date is set
                if (taskToCreate.IsReminderSet 
                    && myTaskComponentController.remCon.taskID.ActivityDate != null) {
          //set the reminder time based on the reminder class's ActivityDate
          //The date and time in the reminder class is converted into a datetime by the convertToDatetime() method
                    taskToCreate.ReminderDateTime = 
                    system.debug('taskToCreate.ReminderDateTime --> ' + taskToCreate.ReminderDateTime);
        //set the whatId to the Opportunity Id            
                taskToCreate.WhatId = leadConvertResult.getOpportunityId();
                //set the whoId to the contact Id
                taskToCreate.WhoId = leadConvertResult.getContactId();
                //set the subject
                taskToCreate.Subject = myTaskComponentController.taskID.Subject;
                //set the status
                taskToCreate.Status = myTaskComponentController.taskID.Status;
                //set the activity date 
                taskToCreate.ActivityDate = myTaskComponentController.taskID.ActivityDate;
                //set the Priority 
                taskToCreate.Priority = myTaskComponentController.taskID.Priority;
                //set the custom field Primary Resource (this is a custom field on the Task showing an example of adding custom fields to the page)
                taskToCreate.Primary_Resource__c = myTaskComponentController.taskID.Primary_Resource__c;
                //set the Description field which comes from the leadConvertTaskDescComponent
                taskToCreate.Description =  myDescriptionComponentController.taskID.Description;

        //if the sendNotificationEmail variable in the leadConvertTaskDescComponent class is set then send an email
                if (myDescriptionComponentController.sendNotificationEmail)
                  //create a new DMLOptions class instance
                    Database.DMLOptions dmlo = new Database.DMLOptions();
                    //set the trigger user email flag to true
                    dmlo.EmailHeader.triggerUserEmail = true;
                    //insert the task
                    database.insert(taskToCreate, dmlo);
                  //if the sendNotificationEmail field was not checked by the user then simply insert the task
                    insert taskToCreate;
            // redirect the user to the newly created Account
            PageReference pageRef = new PageReference('/' + leadConvertResult.getAccountId());
            return pageRef; 

            //if converting was unsucessful, print the errors to the pageMessages and return null

            return null;
        return null;

    //this method will take database errors and print them to teh PageMessages 
    public void PrintErrors(Database.Error[] errors)
        for(Database.Error error : errors)
            ApexPages.Message msg = new ApexPages.Message(ApexPages.Severity.ERROR, error.message);
    //This method will put an error into the PageMessages on the page
    public void PrintError(string error) {
        ApexPages.Message msg = new 
            ApexPages.Message(ApexPages.Severity.ERROR, error);
    // given a date and time, where time is a string this method will return a DateTime
    private DateTime convertToDatetime(Date d, string t) {
        String timeFormat = DateTimeUtility.LocaleToTimeFormatMap().get(UserInfo.getLocale());
        //if the local of the user uses AM/PM 
        if (timeFormat != null && timeFormat.endsWith('a')) {
          //split the time into 2 strings 1 time and 1 am r pm
            string [] reminderTime = t.split(' ');
            //split the time into hour and minute
            string hour = reminderTime[0].split(':')[0];
            string min = reminderTime[0].split(':')[1];
            //get the am or pm
            string AM_PM = reminderTime[1];
            //turn the hour into an integer
            integer hr = Integer.valueOf(hour);
            //if the am/pm part of the string is PM then add 12 hours
            if (AM_PM.equalsIgnoreCase('PM')) hr += 12;
            //return a new DateTime based on the above information
            return (
        //If the user's local does not use AM/PM and uses 24 hour time
        else {
            //split the time by a : to get hour and minute
            string hour = t.split(':')[0];
            string min = t.split(':')[1];
            //turn the hour into an integer
            integer hr = Integer.valueOf(hour);
            //return a new DateTime based on the above information
            return (

The "Bypass New Business Tasks" field is a field on the Lead object. I'd like to map it to there.