Am stuck and unable to understand how shall i pass the lookup field value to controller. I am using get set,but it dint show any variable value in logs for the lookupfield ? Am stuck and not sure what to do. Can anyone please guide.

<apex: inputField value = "{!XYZ.AccountId}" />


 <apex:page standardcontroller=Contact extension="testLookup">
    <apex:inputfield value = "{!Contacts.AccountId} label = OldeAccount>
     <apex:variable value = "{!Contacts.AccountId}  var =' OldA'/>
<apex:inputfield value = "{!Contacts.AccountId} label = NewAccount>
<apex:variable value = "{!Contacts.AccountId}  var =' NewA'/>


public with sharing testLookup
    public string OldA{get;set;}
    public string NewA {get;set;}

   public void save()
     contact con = [select accountype,accountnumber from account where id=: OldA];
  • 1
    Please post the controller code as well with related snippets of the VF page – highfive Dec 20 '14 at 16:49
  • Note that if the field is really accountId, then XYZ must be a standard object as fields that don't end in __c won't appear on custom objects – cropredy Dec 22 '14 at 18:25
  • @highfive in my requirement i need the standard controller with the extnsion....and am not clear on passing the value selected by the person in lookup onto controller. May be as the lookup is represted as contacts.AccountId? Thanks – user10727 Dec 26 '14 at 0:20

You need to have something happen to set the value.

use a command button to call a method in the controller. Once you do that the setter will fire and the value will be accessible to the controller.

You are also going about it all wrong. You do not need the variable...See this example:


<apex:page standardController="Account" extensions="testextension">

    <apex:inputField value="{!Account.Name}"/>

   <apex:commandButton action="{!save}" rerender="msgs"/>



public class testextension{

       public Account a {get;set;}

        public testextension(apexPages.standardController con){
            a = (Account)con.getRecord();

        public void save(){
            system.debug(a.Name); //Should be whatever you entered on the page

| improve this answer | |
  • Thanks Eric...This logic actually works well with any type of field. – user10727 Dec 26 '14 at 23:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.