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
Alex Sherwood 1Alex Sherwood 1 

Add field to Visualforce Page1

I've downloaded an unmanaged package - Convert Lead - Custom Lead Conversion Process (https://appexchange.salesforce.com/listingDetail?listingId=a0N3000000B4sHpEAJ) from the AppExchange which provides a template for a Lead Convert Visualforce page. I now want to add my field Annual_Settlement_Value__c to the page - it looks like I need to modify the leadConvertCoreComponent in order to do this.

But I can't find any documentation which includes sample code that resembles the code that's already in this component so I can't see where to add the field and how to format the code. If anyone could provide an example, it would be much appreciated.
<!-- 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="{!Lead.name}"/>

<!-- 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"/>
               
        </apex:pageBlockButtons>           
       
        <!-- 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 -->
    
    </apex:pageBlock>
       
<!-- This is the closing tag for the form -->

</apex:form>
   
<!-- This is the closing tag for the page -->
    
</apex:page>
<!-- 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 {
            width:0;
            height:0;
            border:0;
            padding:0;
            margin:0;
        }
    </style>

    <!-- This is the attribute that holds the lead to convert -->
    <apex:attribute name="LeadToConvert" 
        description="The lead to convert"
        type="Lead" 
        assignTo="{!leadConvert}"
        required="true"/>

    <!-- This attribute is used for the leadConvertController to interact with this component's controller -->
    <apex:attribute name="thepageController"
      type="PageControllerBase"
      assignTo="{!pageController}"
      required="true"
      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" />
        </apex:pageBlockSectionItem>
        
        <!-- 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>
        
             
        <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" 
                        action="{!accountChanged}" 
                        rerender="opportunityName, ViewLink"
                         />     
                    <apex:selectOptions value="{!accounts}"/>
                    
                </apex:selectList>
                
                <!--  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" 
                        action="{!accountLookedUp}" 
                        rerender="accountList, opportunityName, ViewLink"
                         />
                        
                </apex:inputField>
                
                <!-- 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 = window.open('/{!selectedAccount}/p', 'accountview', 'top=40, left=40,scrollbars=yes, height=450, width=800');newwindow.focus();} else {alert('You can only view existing accounts.');}"
                />
                
            </apex:outputPanel>
        </apex:pageBlockSectionItem>
        
        <!-- Opportunity section -->
        <apex:pageBlockSectionItem id="oppSection" >
            
            <apex:outputPanel id="oppPanel" >
                <apex:outputLabel value="Opportunity Name" for="opportunityName" />
            </apex:outputPanel>
            
            
            <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"/>
                </apex:outputPanel>
                
                <!--  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" 
                        
                        rerender="opportunityPanel"
                         />
                </apex:inputCheckbox>
                Do not create a new opportunity upon conversion.
            </apex:outputPanel> 
            </apex:outputPanel>
        </apex:pageBlockSectionItem>
        
        <!-- 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}"/>
                </apex:selectList> 
            </apex:outputPanel>
        </apex:pageBlockSectionItem>
    </apex:pageBlockSection>
    
</apex:component>


 
Andy BoettcherAndy Boettcher
The Component works pretty much just like a Visualforce page does.

Question - which object is Annual_Settlement_Value__c on?

To get it on the page, you'll need to do two things:
  1. Go into the Component's controller (leadConvertCoreComponentController) and add that to the Lead SOQL if that field is on Lead.
  2. Go to the Component itself and add an <apex:pageBlockSectionItem> or <apex:inputField> in the section that corresponds to the object in question.
Alex Sherwood 1Alex Sherwood 1
Thanks Andy..Annual_Settlement_Value__c is an Opportunity field. I'll give your suggestion a go and let you know how I get on, that helps a lot.
Andy BoettcherAndy Boettcher
Cool!  I'd aim for about Line 98 on the Component:
 
<!-- Opportunity Name -->
<apex:inputField required="false" 
          value="{!opportunityID.Annual_Settlement_Value__c}" id="opportunityASV"/>

 
Alex Sherwood 1Alex Sherwood 1
I've added the lines that you posted in your last comment and was able to save the Component without any issues.

But there isn't an SOQL query for Opportunities in the leadConvertCoreComponentController or in any of the other Classes in the package. Rather than posting all of the code from this package & swamping the post, I've saved it in a Gist (https://gist.github.com/aplssf/87d701216c559072e9b4), would you mind taking a look and letting me know what else I need to modify in order to display the field? I'm reasonably comfortable working with Apex code so I should be able to make any necessary modifications to the Classes..