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
DonJDonJ 

Return ID from custom object in Contact

I have a VF page with an input field to allow the user to input the value of a custom field on a contact record. I need to lookup the custom field to get the id on this record to then display the contact record. I am using the standard contact controller but can add an extension if I need to look up the custom field. Is there any sample code that anyone has that might give me a jump start on this? I am really looking for suggestions on the fastest method to get the lookup completed since this will be done hundreds if not thousands of times per day and speed is therefore very important.
 
Richie DRichie D

Hi,

If your custom field points to another custom or standard object then just use apex:inputfield tag like:

Code:
<apex:inputfield value="{!MyObject.MyField__c}"/>

For example, if you are doing a lookup to a contact then you get the 'lookup contact' link icon next to the textbox. Thats all there is to it. You'll also get the label associated to the item included as well.

Otherwise you'll have to build your own search or list control (e.g. a SelectList) and link it yourself.

If you are coming from the item to link to then pass it in in the url queryString and set this in your constructor.

Rich.

DonJDonJ

Hi Richie,

Thanks for your reply, I do appreciate it. I should have explained this is in a bit more depth. I want use a barcode scanner to collect a value for a custom field on the contact object (this is the input field per your example), use that value (without any user intervention) to lookup the contact that value is related to and display it's contact detail section to the VF page.

Don

XactiumBenXactiumBen
If I understand this correctly, you are creating a search screen that a user can enter a barcode value, which will come back with a contact if one exists that has the value of the user inputted barcode value.

If this is the case, then you will need to create a controller extension that gets a contact.  Something like this:

Code:
public class extension
{
     public Contact getContact()
     {
          Contact[] contact = [Select Id, Name From Contact Where Custom_Field__c = :userInput];
          if (contact.size() == 1)
          {
               return contact.get(0);
          }
          return null;
     }
}

 This function will return a contact if one has been found or return null if a contact hasn't been found (or multiple contacts have been found).