You need to sign in to do that
Don't have an account?

Get the value of the lookup field in controller onchange
I am using a custom controller(Not extension controller) for a VF page. That VF page has a lookup to Accounts. I want the selected lookup field value in my controller. I am using actionSupport for this(On change of lookup).
Any help?
Hi,
you dont need to use action support (unless i misunderstood and you want to use it).
to have a lookup in a visualforce page, you need to have an <apex:inputField> tag in your page, in which the value attribute is binded to a lookup to account. e.g <apex:inputField value="{!Contact.AccountId}" /> and the controller contains a public varibale called "Contact"
if you use it this way, you can access the value in your controller by accessing Contact.AccountId.
If this solves the issue for you, please mark it as resolved. if not, please reply
No, I have already examined this when I built the page ..... I am not using extension controller.... I am using a custom controller... It gives me a null value....
It shouldnt really matter whether its an extension or a custom controller.
could you post the relevant parts of your code?
Thanks for your reply. Please look at this code. I have left with no hope. :) I tried removing immediate = true in actionsupport, but when its removed, it is giving me a blank value, which is a preevious value when the page first loaded.
Class:
Page:
Shailesh ,
This blog info Helps me a lot ,sounds like you are facing similar requirement :
http://blog.jeffdouglas.com/2011/08/12/roll-your-own-salesforce-lookup-popup-window/
Let me know ,if you need to understand anything on this . I am able to develop my requirement based on this .
Warm Regards,
Shailesh,
I know its been a year since you posted this. A little late question but were you able to find out the solution to your problem?
Hi Shailesh / Achilles21
If your requirement is to get the value of selected lookup into apex then given below is the sample code.
I have an object A__c which has lookup field on Account and field name is Account__c
VF:
<apex:page standardController="A__c" extensions="Vishal">
<apex:form>
<apex:inputfield value="{!A__c.Account__c}">
<apex:actionSupport event="onchange" action="{!AccountPopulated}" />
</apex:inputField>
</apex:form>
</apex:page>
Apex:
public class vishal
{
public vishal(ApexPages.StandardController std) {
stdCtrl=std;
}
private ApexPages.StandardController stdCtrl;
public void AccountPopulated()
{
A__c cont=(A__c) stdCtrl.getRecord();
system.debug('>>>>>>>>>>>>>>>>>>>>>'+cont.Account__c);
}
}
Regards,
Vivek Negi
thanx... :) :)
If there is a value stored previously in the lookup field , it works very fine, it get a value, (case 1)
but if there is no a value stored previously in the lookup field, it get a null value, (case 2)
what I am searching is to get the value you select in the lookup popup window (case 2)
Any idea
Thank you
Rregards!!!
I also noticed those following cases:
WORKING : <apex:actionSupport event="onchange" action="{!xxx}" immediate="false" />
WORKING : <apex:actionSupport event="onchange" action="{!xxx}" />
NOT WORKING : <apex:actionSupport event="onchange" action="{!xxx}" immediate="true" />
NOT WORKING : <apex:actionSupport event="onchange" action="{!xxx}" reRender="something" />
NOT WORKING : <apex:actionSupport event="onchange" action="{!xxx}" immediate="true" reRender="something" />
If anyone found a solution it would be great to share.
Regards