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
SA_DevSA_Dev 

How to give value to a lookup field??

Hi All,

 

We are working on a custom VF page its functionality is given below:-

 

We have two custom fields on Lead :- 1) Account lookup  2) Contact lookup

 

We are using both the fields in VF page. 

 

Requirement:- If user select any value from contact lookup on VF page, then its related Account should populate automatically on the same VF(Lead edit) page.

 

We are  able to do the same on other fields like(text fields, piclist fields), but as this(account field) is a lookup field we are not able to do it.

 

e.g.:- For text field we can use <apex:inputText value="value fetched from Contact" />

         but we are not able to do the same for lookup field.

 

Kindly help us with the same, any answer will be much appreciated...

 

 

Regards

Sunil Arora

 

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
ThomasTTThomasTT

If you are trying to set a value in the SObject lookup field in the controller, you just put the record ID in the lookup field.

 

If you are trying to set a value in the text field from Javascript, then it's little bit different.

If the lookup <apex:inputField> id is "aaa:bbb:ccc", then you need to set the Name in the <input id="aaa:bbb:ccc"> and the record ID in the <input id="aaa:bbb:ccc__lkid">. There is a SFDC javascript internal function called "lookupPick()" to do that, but you can do it by yourself. Don't forget to submit the data to controller.