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
raghu123raghu123 

Displaying lookup field in VF page

Hi Guys,

          

                    I need to display lookup fields in a Table of VF page. I am getitng Id Instead of Name..Can Anyone Help me on this.

 

Appriciate your help..

Thank You.

Raghu

ngabraningabrani

Raghu,

From Visualforce you can call an Apex method that will perform a SOQL query to get the name from the Id. The SOQL query could look something like

[select object.name from object where object.id = :id]

GobbledigookGobbledigook

If what you want to do is just display a Lookup Field related to a Field from any Object:

 

<apex:inputField value="{!ObjectReferencedInStandardController.LookupFieldInObject}" />

 

So if you had a Custom Object  named Deals__c and a custom Lookup field Account__c:

<apex:page standardController="Deals__c" >
<apex:inputField value="{!Deals__c.Account__c}" />

 

 

If you want to reference multiple lookup Fields from Multiple Objects, you should define a Controller extension and instantiate an Object for each Field needed.  

 

So:

 

VF Page:

<apex:page standardController = "Deals__c" extension="CustomExtension"> 

<apex:inputField value="{!d.Account__c}" /> 
<apex:inputField value="{!e.Contact__c}" />
etc...

 

 

And Controller

 

 

public class CustomExtension
{
  public Deal__c d {get;set;}
  public AnotherCustomObject e {get;set;}

  ... Add logic here.

 

 

 Hope this helps.