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
janardhan mjanardhan m 

pass standard controller input field lookup value to conroller class

 lookup__c is a standard lookup field in my object Student__c.

<apex:inputField value="{!Student__c.lookup__c}" /> 

I want to pass selected lookup field value in visualforce page to extension controller class.


            
Best Answer chosen by janardhan m
janardhan mjanardhan m
public class sndmail {
public student__c stu;

    public sndmail(ApexPages.StandardController controller) {
    this.stu= (student__c)Controller.getRecord();

    }
public String getGreeting() {
return  stu.lookup__c;
  }

All Answers

Suneel#8Suneel#8
Lookup id will be updated on the object.so lookup__c will contain the id of the updated record.If you need value of it, you need to query and get the value.Below is sample  c.account id displays updated account id on contact VF page

        Contact c;
        c=(Contact)sc.getRecord();
        System.debug('-->'+c.accountid);  


 
janardhan mjanardhan m
Hi suneel,

<apex:inputField value="{!Student__c.lookup__c}" /> 
  
here lookup__c is self lookup with student__c,how to get id of the selected field in controller class.

Thanks in advance.
 
Suneel#8Suneel#8
Field lookup__c itself holds the id of the Student record Though it is a self lookup,logic remains the same.You can post your controller code so that i can suggest some modification
janardhan mjanardhan m
public class sndmail {
public student__c stu;

    public sndmail(ApexPages.StandardController controller) {
    this.stu= (student__c)Controller.getRecord();

    }
public String getGreeting() {
return  stu.lookup__c;
  }
This was selected as the best answer
Suneel#8Suneel#8
Yes you code looks good. Now stu.lookup__c will return you id of the currently selected student record.Isn't it?What do you want to do further?
janardhan mjanardhan m
But it shows null value not the id.I don't understand the mistake.
Suneel#8Suneel#8
How are you calling getGreeting method?Can you post your VF page code as well?