I am trying to pass an inputfield back to the controller.

NOTE: Do not treat "HBS ID" as a value representing a Salesforce ID. This value is similar to an employee ID you have at work.

Goal: give user ability to select Employee__c object record. This lookup value is stored in Employee__c field on Employee_Session__c.

Page section:

 <apex:form >
    <div id="section">
        <apex:pageblock tabStyle="Employee_Session__c" title="Merger Details">
            <apex:pageBlockSection columns="2">
                <apex:outputLabel value="Current HBS ID:" style="font-weight:bold;"/>
                <apex:outputLabel value="New HBS ID:" style="font-weight:bold;"/>
                <apex:outputLabel value="{!empName}" style="font-weight:bold;"/>
                <apex:inputField label="HBS ID:" id="pickerHBSID" value="{!emp.Id}" required="true" />
            <apex:pageBlockSection columns="1">
                <apex:commandButton action="{!mergeRecords}" title="Save" value="Save">

Controller Code:

 public class EmpMerge_Controller {

    list<Employee_Session__c> esList = new list<Employee_Session__c>();
    list<Task> eTasks = new list<Task>();
    public Id empId {get; set;}
    public String empName {get; set;}
    public Employees__c emp {get;set;}

    public EmpMerge_Controller() {
        //empId = ApexPages.CurrentPage().getparameters().get('id');
        empId = 'a00f0000006xeI6';
        //empName = ApexPages.CurrentPage().getparameters().get('Name');
        empName = 'TRE1';

        emp = new Employees__c();

    public List<Employee_Session__c> getEmpSessions() {
        esList = [Select Id,Name,Employee__r.Name,Specialist__c,CreatedDate,LastModifiedDate 
                  FROM Employee_Session__c 
                  WHERE Employee__c = :empId];

        return esList;

    public list<Task> getTasks(){
        eTasks = [Select Id,Subject,CreatedDate FROM Task WHERE WhatId = :empId];
        return eTasks;

    public PageReference mergeRecords(){
        system.debug('empName = ' + emp.Name);
        system.debug('empId = ' + emp.ID);

        for(Employee_Session__c es:esList){
            es.Employee__c = emp.Id;
        for(Task t:eTasks){
            t.WhatId = emp.Id;
        update eTasks;
        update esList;

        return null;

What it looks like: (not getting a box where i can pick the new Employee__c record). I have tried emp.Name which gives me white box but I don't get the search popup option.

enter image description here

1 Answer 1


An SObject field such as Employee_Session__c.Employee__c is automatically passed back to the server and set in the field on the controller.

But for that to work in your case you need the empSession property to be set to an instance of Employee_Session__c either queried from the database if you want to edit the value or just a empSession = new Employee_Session__c(); set in e.g. the constructor if this is purely data entry with no pre-existing value. Probably the former in your case so add this to the constructor:

empSession = getEmpSessions().get(0);


public PageReference mergeRecords() {
    update empSession;
    return null;


To get a lookup field rendered (a text field for the name, a hidden field for the ID and a button to display a search pop-up) you need to use a Lookup field not an ID field or a Name field. This is just a design chose Salesforce made.

  • Actually I am doing the latter. I need to capture the new ID so I can use it for updating multiple object records that all lookup to Employee.
    – Matt M
    Jun 14, 2016 at 20:48
  • I have updated my original post with updated controller and page. I also updated most of the description text to describe current problem.
    – Matt M
    Jun 14, 2016 at 21:25
  • @MattM See my PS; think your original code was a bit closer.
    – Keith C
    Jun 14, 2016 at 21:32
  • Lol, ok I just figured it out. Yes Keith my original code was closer.
    – Matt M
    Jun 14, 2016 at 21:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .