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
suji srinivasansuji srinivasan 

how to fetch data for a lookupfield in visualforce page?

When i try to fetch data for a lookupfield .i got only id .can anyone suggest me what needs to be done to fetch values for the lookup fields.

Thanks in advance
Best Answer chosen by suji srinivasan
mukesh guptamukesh gupta
HI Suji,

Just try below code:-
<apex:page standardController="Salary_Detail__c" extensions="salarydetails" renderAs="pdf" > <table>
<apex:form > 
<apex:repeat value="{!Salary_Detail__c.Employee_ID__r}" var="emp" >
 <tr>
   <td >Emp Code</td>
    <td><apex:inputText value="{!emp.Name}"> </apex:inputText> </td>  
 </tr>
</apex:repeat>
</apex:form>
</table>

if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh

All Answers

Sai PraveenSai Praveen (Salesforce Developers) 
HI Suji,

What I guess is you can only get the id from the visualforce page if we have lookup for it. If you need the value for that then you have to write some logic for the same as you want the value for it.

It would be more clear if you share the code.

Let me know if you face any issues.

If this solution helps, Please mark it as best answer.

Thanks,
mukesh guptamukesh gupta
Hi Suji,

Please follow simple example 

http://himanshurana.in/auto-populate-visualforce-page-field-lookup-fields/

if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh
suji srinivasansuji srinivasan
Hi sai,

Employee Id is my lookup field which i am fetching from another app

VF page:
<apex:page standardController="Salary_Detail__c" extensions="salarydetails" renderAs="pdf" >
<table>
 <apex:form > <apex:repeat value="{!Salary_Detail__c}" var="a" > <tr>

<td >Emp Code</td>
<apex:inputText value="{!Salary_Detail__c.Employee_ID__c}"> </apex:inputText> </td>  </tr>
</apex:repeat></apex:form ></table>

Apex class:
public class salarydetails {
public Salary_Detail__c SalaryDetail{get;set;}
        private ApexPages.StandardController controller;
        public SalaryDetails(ApexPages.StandardController controller){
                //SalaryDetail = Salary_Detail__c();
        }

        Public PageReference saveRecord() {
                insert SalaryDetail;
                PageReference pr = new PageReference('/'+SalaryDetail.id);
                pr.setRedirect(true);
                return pr;
        }
}

​​​​​​​thanks in advance.
mukesh guptamukesh gupta
Hi Suji,

Please use below code:-

VF:
 
VF page:
<apex:page standardController="Salary_Detail__c" extensions="salarydetails" renderAs="pdf" >
<table>
 <apex:form > <apex:repeat value="{!Salary_Detail__c}" var="a" > <tr>

<td >Emp Code</td>
<apex:inputText value="{!Salary_Detail__c.Employee_ID__r.Name}"> </apex:inputText> </td>  </tr>
</apex:repeat></apex:form ></table>


if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh

 
suji srinivasansuji srinivasan
Hi mukesh,
As you suggested i changed it showing like invalid object
mukesh guptamukesh gupta
HI Suji,

Just try below code:-
<apex:page standardController="Salary_Detail__c" extensions="salarydetails" renderAs="pdf" > <table>
<apex:form > 
<apex:repeat value="{!Salary_Detail__c.Employee_ID__r}" var="emp" >
 <tr>
   <td >Emp Code</td>
    <td><apex:inputText value="{!emp.Name}"> </apex:inputText> </td>  
 </tr>
</apex:repeat>
</apex:form>
</table>

if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh
This was selected as the best answer