+ Start a Discussion
Vandana RattanVandana Rattan 

Help to access VisualForce fields in Controller

I have made a custom LeadConvert page. I need to pass following values from the page to the controller. How can I achieve this?

Controller snippet:--

<apex:pageBlockSectionItem >
            <apex:outputLabel for="Subject">Subject</apex:outputLabel>
            <apex:inputField value="{!Task.Subject}" id='tskSubject' >
             	<apex:param value="{!Task.Subject}" assignTo="{!tskSubject}"/>
             </apex:inputField>
          </apex:pageBlockSectionItem>
          <apex:pageBlockSectionItem >
            <apex:outputLabel for="Type">Type</apex:outputLabel>
            <apex:inputField value="{!Task.Type}" id='tskType'/>
          </apex:pageBlockSectionItem>


NaveenReddyNaveenReddy
Hi,
Use PageReference Class
A PageReference is a reference to an instantiation of a page. Among other attributes, PageReferences consist of a URL and a set of query parameter names and values.
Example.
ApexPages.currentPage().getParameters()

For more info pls refer below link
https://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#CSHID=apex_System_PageReference_getParameters.htm|StartTopic=Content%2Fapex_System_PageReference_getParameters.htm|SkinName=webhelp

Regards,
Naveen
SSE , Salesforce CI expert group
http://www.autorabit.com"
Vandana RattanVandana Rattan
It's not working for me. Getting null values.
Vandana RattanVandana Rattan
Here is my complete Visualforce Page:-

<apex:page standardController="Lead" extensions="LeadConvertController">
    <apex:includescript value="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js" />
     <apex:sectionHeader title="Convert {!$ObjectType.Lead.label}" subtitle="{!Lead.name}"/>
    <apex:form id="leadForm">
        <apex:pageBlock mode="edit" >
       
        <apex:pageblockbuttons >
                <apex:commandbutton value="Convert" action="{!ConvertLead}"/>
            	<apex:commandbutton value="Duplicate Contacts" action="{!getDuplicateContacts}"/>
                <apex:commandbutton value="Cancel" action="{!Cancel}"/>
        </apex:pageblockbuttons>
        
        <apex:pageblocksection id="LeadConvertPBS" title="Convert Lead">
        	<apex:pageBlockSectionItem >
            <apex:outputLabel value=" Record Owner" for="Record Owner"/>
                <apex:inputField value="{!lead.OwnerID}" id="recOwner1" />
            
          	</apex:pageBlockSectionItem>
            
            <apex:pageBlockSectionItem >
            	<apex:outputLabel for="Account Name">Account Name</apex:outputLabel>
             <!--<apex:inputField required="true" id="company" value="{!lead.Company}" />-->
             <apex:selectList id="soAccount" value="{!value}" label="Account Name" size="1">
                 <apex:selectOptions value="{!lstCompanyInfo}"/>
                   
             </apex:selectList>
          </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="Oppt Name">Opportunity Name:</apex:outputLabel>
             <apex:inputField required="true" id="opptName" value="{!lead.Company}" />
          </apex:pageBlockSectionItem>
          <apex:pageBlockSectionItem >
                      <apex:outputLabel for="ConStatus">Converted Status:</apex:outputLabel>
             <apex:inputField id="ConStatus" value="{!lead.Status}" />
          </apex:pageBlockSectionItem>
          <apex:pageblockSectionItem >
             <!-- <apex:outputLabel for="no oppty">Do not create new opportunity upon conversion</apex:outputLabel>
              	<apex:inputCheckbox id="noOppty"/>-->
               
          </apex:pageblockSectionItem>
        </apex:pageblocksection> 
        <apex:pageBlockSection title="Task Information" columns="1" id="TaskInformation">
         <apex:pageBlockSectionItem >
            <apex:outputLabel for="Subject">Subject</apex:outputLabel>
            <apex:inputField value="{!Task.Subject}" id="tskSubject" onchange="setTskSubject">
             	
             </apex:inputField>
          </apex:pageBlockSectionItem>
          <apex:pageBlockSectionItem >
            <apex:outputLabel for="Type">Type</apex:outputLabel>
            <apex:inputField value="{!Task.Type}" id="tskType" onchange="setTskType"/>
          </apex:pageBlockSectionItem>
         
        <apex:pageBlockSectionItem >
            <apex:outputLabel for="DueDate">Due Date</apex:outputLabel>
            <apex:inputField value="{!Task.ActivityDate}" id="tskDueDt"/>
        </apex:pageBlockSectionItem>
        <apex:pageBlockSectionItem >
            <apex:outputLabel for="Comments">Comments</apex:outputLabel>
            <apex:inputField value="{!Task.Description}" id="tskDesc"/>
          </apex:pageBlockSectionItem>
        
       </apex:pageBlockSection>    
     <apex:pageBlockSection title="Additional Information" columns="1" id="AdditionalInformation">
         <apex:pageBlockSectionItem >
            <apex:outputLabel for="Status">Status</apex:outputLabel>
            <apex:inputField value="{!Task.Status}" id="tskStatus"/>
          </apex:pageBlockSectionItem>
    <apex:pageBlockSectionItem >
            <apex:outputLabel for="Priority">Priority</apex:outputLabel>
            <apex:inputField value="{!Task.Priority}" id="tskPriority"/>
          </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:pageblocksection id="DuplicateContacts" title="Duplicate Contact List"> 
            <apex:pageBlockTable value="{!lstDupContact}" var="ct" title="Duplicate Contacts">
                <apex:column headerValue="Select" >
                    <apex:actionSupport event="onclick" action="{!selectContact}" rerender="all">
                        <input type="radio" value="con"/>
                        <apex:param value="{!ct.id}" name="conid" assignTo="{!contIdChosen}"/>
                    </apex:actionSupport>
                </apex:column>
                <!--<apex:column value="{!ct.id}"/>-->
                <apex:column value="{!ct.EA_Member_No__c}"/>
                <apex:column value="{!ct.firstName}"/>
                <apex:column value="{!ct.lastName}"/>
                <apex:column value="{!ct.email}"/>
                <apex:column >
                    <apex:commandButton value="Select" action="{!selectContact}" rerender="all">
                        <apex:param name="contIdParam" value="{!ct.id}" assignTo="{!contIdChosen}"/>	
                    </apex:commandButton>
                </apex:column>
            </apex:pageBlockTable>
        </apex:pageblocksection>
            
        </apex:pageBlock>
        
    </apex:form> 
    
</apex:page>

I am having problems in accessing fields in Task information section. Kindly help.
NaveenReddyNaveenReddy
Hi Vandana,

  You are extending Standard Controller Lead and you are trying to access fields from Task which resulting a issue.

To achieve your requirement you need to write a Custom Controller.Pls refer below links..

https://developer.salesforce.com/forums/ForumsMain?id=906F000000096v4IAA

http://salesforce.stackexchange.com/questions/17364/visualforce-display-fields-from-multiple-objects

Mark it as best answer if it solves your problem.

Regards,
Naveen
Vandana RattanVandana Rattan
Thanks Naveen. I have already made a Custom controller given below. But how do I get the Task fields from visualforce to this controller?
public class LeadConvertController{
    Lead lead;
    Task tsk;
    
    //ApexPages.StandardSetController stCon;
    public List<Contact> lstDupContact {get; set;}
    public String contIdChosen {set;get;}
    public String value {get;set;}
    public String tskSubject {get;set;}   
    public String tskType {get;set;}
    
     //public ApexPages.StandardController myLeadController {get; set;}

    //public Lead Lead {get; set;}

    public ApexPages.StandardController myTaskController {get; set;}

    public Task Task {get; set;}

    public ApexPages.StandardController standardContactController;

    
    public LeadConvertController(ApexPages.StandardController controller) {
        standardContactController = controller;
        
        Lead lead = (Lead)controller.getRecord();
        myTaskController = new
		//this.lead = (Lead)controller.getRecord();
        //stCon = controller;
	}
    
       
    public PageReference ConvertLead(){
        System.debug('Inside Lead Convert Controller');
        //String sub = System.currentPageReference().
        
        //System.debug('tskSubject >>>>' + getTskSubject());
         System.debug('tskType >>>>' + ApexPages.currentPage().getParameters().get('tskType'));
        Database.LeadConvert lc = new database.LeadConvert();
        lc.setLeadId(lead.Id);
        Lead leadRecord = [SELECT firstName, lastName, email from lead where id =: lead.Id];
        System.debug('lead id >> ' + lead.id);
        System.debug('lead Owner >> ' + lead.OwnerId);
        System.debug('contIdChosen in ConvertLead function >>>' + contIdChosen);
        System.debug('value >>>>' + value);
        System.debug('tskSubject >>>>' + Task.Subject);
        if(value != '1'){
            lc.setAccountID(value);
        }
        //GroupMember grpMember = [Select UserOrGroupId from groupmember where groupid= :lead.OwnerId];
        //System.debug('GroupMember--->' + grpMember.UserOrGroupId);
        //lc.setOwnerId(grpMember.UserOrGroupId);
        lc.setConvertedStatus('Qualified'); 
        if(contIdChosen != null)
        	lc.setContactId(contIdChosen);
            
            
        Database.LeadConvertResult lcr = Database.convertLead(lc); 
        if(lcr.isSuccess()){
            String aId = lcr.getAccountId();
            
           
            
            
            PageReference redirect = new PageReference('/' + aId);
            redirect.setRedirect(false);
            return redirect;
        }
        return new PageReference('/'+'');
       //return null;
    }
    
    public List<SelectOption> getlstCompanyInfo() {
	    String strCompanyWildcard = '%' + lead.Company + '%';
	    List<Account> lstAcct = [SELECT Id, Name, Owner.Name FROM Account WHERE Name LIKE :strCompanyWildcard];
	    List<SelectOption> lstCompanies = new List<SelectOption>();
    
        // Add New Account if not found
    
        lstCompanies.add(new SelectOption('1','Create New Account: ' + lead.Company));
    
        // Add found Accounts to SelectList
    
        for(Account a : lstAcct) {
             lstCompanies.add(new SelectOption(a.Id, 'Attach to Existing: ' + a.Name + ' (' + a.Owner.Name + ')'));
        }

        return lstCompanies;       

}

    
    
    public pageReference getDuplicateContacts(){
        System.debug('Inside getDuplicateContacts');
        Lead leadRecord = [SELECT firstName, lastName, email from lead where id =: lead.Id];
        System.debug('lead id >> ' + lead.id);
        System.debug('lead Owner >> ' + lead.OwnerId);
        
        lstDupContact = [SELECT EA_Member_No__c, firstName, lastName, email from Contact where (firstName =: leadRecord.FirstName OR lastName =: leadRecord.LastName) AND email =: leadRecord.email];
            System.debug('lstDupContacts >>>' + lstDupContact);
           
        if(lstDupContact.size() > 0){
        	ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR, 'Duplicate Contacts Found: ' + lstDupContact);

			ApexPages.addMessage(myMsg);
            return null;
        }
        else{
            ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR, 'No Duplicate Found');

			ApexPages.addMessage(myMsg);
            
            return null;
        }
        return new PageReference('/'+'');
    }
    
    public PageReference selectContact()
    {
        System.debug('Inside selectContact >>>>');
        System.debug('contIdChosen>>>' + contIdChosen);
        //string selectconid = System.currentPagereference().getParameters().get('conid');
        //system.debug('selected id:::::::::::::::::::::::'+selectconid);

        /*System.debug('stCon>>>' + stCon);
        System.debug('stCon selected>>>' + stCon.getSelected());
        // do something with the selected records
        for ( Contact con : (Contact[])stCon.getSelected() )
        {
            System.debug('Contact Name = ' + con.firstName);
        }*/
        return null;
    }
    
    public Task getTask(){
        Task tsk = new Task();
        return tsk;
	}

    
    public List<Contact> getLstDupContact(){
        return lstDupContact;
    }
    
   
}