+ Start a Discussion
Rahul SharmaRahul Sharma 

Best way to display a lookup field?

Hello board,

 

I would like to know whats the best way to display an input lookup field in a custom page.

I know if we want to show a account lookup, we can do it by using a contact object in controller and use objContact.AccountId as a input field in a page.

Thats works in case of lookup but in case of master detail it shows a outputfield if we try to prepopulate a master object.

Any ideas?

Best Answer chosen by Admin (Salesforce Developers) 
Rahul SharmaRahul Sharma

In that example too its lookup relationship between Account and contact.

Thanks anyways.

Outputfield is displayed due to the fact that master cant be changed for a detail record once selected.

So, Its the standard way and it wont allow to change a master once prepopulated.

All Answers

UVUV

How you are prepopulating the field???

Rahul SharmaRahul Sharma

Hi Umesh,

 

I took a object instance of the detail which has reference of Master object in the controller.

And in constructor i assigned the object instance with record.

Now to show the lookup selector in Custom vf page i'm using a Input field binded with DetailObjectInstance.ParentReferencefield.

But it works/ it allow to select any master for the case when i dont prepopulate. but if i try to prepopulate its shown in outputField instead of input.

 

That may be due to the fact that Master once selected can't be changed, Is there any work around for this?

 

UVUV
Rahul SharmaRahul Sharma

In that example too its lookup relationship between Account and contact.

Thanks anyways.

Outputfield is displayed due to the fact that master cant be changed for a detail record once selected.

So, Its the standard way and it wont allow to change a master once prepopulated.

This was selected as the best answer
UVUV

Yeah thats a limitation of master-detail relationship..