0

I have been trying to figure out a solution for a lookup field for a custom object. The lookup field looks up and grabs the customer number. I'm required to process further on it's Id.

The visualforce page has 2 item:

  1. inputField for the lookup and
  2. Execute button

The problem here I'm facing is that I'm not able to bind the lookup value that is manually entered by the user to the command button for further processing.

Here's what I tried:

  1. Don't want to use extension as Id is not passed on the URL, so cant use getRecord();
  2. Can't read from URL, so no getparameter().
  3. Can do it with a String text, but not with a lookup field.

My VF:

     <b>My Account</b>
    <apex:inputField value="{!Obj.My_Account__c}"/>
    <apex:commandButton value="Go" action="{!Process}"

Apex:

public with sharing class MyController {

public MyObject__c Obj{get;set;}

public MyController (ApexPages.StandardController controller) {
   this.Obj= (MyObject__c )controller.getRecord();

   System.debug('@@Obj'+this.Obj);
}co

 public PageReference Process(){

    //obj.My_Account__c is null       
    MyInput items = new MyInput ();
    items.customers = new List<ID>{'007ID123213Qdf0'}; //this is hardcoded but should be manually from type My_Account__c
    System.debug('My Results' + MyInput.processMe(items) ); // Working perfectly for hardcoded values as I'm not able to pass lookup values to command button    

 return null;
 }
}

Any suggestion how I can do it on my existing controller?

1
  • Your question would be better stated if you included some code. – sfdcfox Dec 14 '17 at 21:05
2

When you're using a standard controller, you should bind to the standard controller object. In other words:

<apex:inputField value="{!MyObject__c.My_Account__c}"/>

This has several other perks as well, such as querying the value from the database when an Id parameter is provided to the page, and automatic loading of the value into the lookup field when you use a button on the related list for the field "My Account", etc.

0

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.