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
sameer123sameer123 

Master detail relationship lookup

Hi all,

is it possible to show lookup icon for master detail relationship on a custom visualforce page???

 

Thank you.

Best Answer chosen by Admin (Salesforce Developers) 
Pradeep_NavatarPradeep_Navatar

It is possible to show lookup icon on custom VF page if you are doing bind this related field using <apex:inputField>.

For Example: if you have object named Test1 and have a custom field named lookTest, which has master-detail relationship to another object named Test2.

 

VF Code :

 

<apex:page StandardController=”Test1__c”>

<apex:pageBlock>

  <apex:inputField value=”{!Test1__c.lookTest__c}”/>

</apex:pageBlock>

</apex:page>

 

Hope this helps.

All Answers

Imran MohammedImran Mohammed

Yes, by default visualforce shows up lookup icon beside the fields that are created using lookup relationship or master-detail relationship.

You have to use <apex:inputField/> tag in your visualforce markup to get the lookup icon.

Pradeep_NavatarPradeep_Navatar

It is possible to show lookup icon on custom VF page if you are doing bind this related field using <apex:inputField>.

For Example: if you have object named Test1 and have a custom field named lookTest, which has master-detail relationship to another object named Test2.

 

VF Code :

 

<apex:page StandardController=”Test1__c”>

<apex:pageBlock>

  <apex:inputField value=”{!Test1__c.lookTest__c}”/>

</apex:pageBlock>

</apex:page>

 

Hope this helps.

This was selected as the best answer
sameer123sameer123

Hi,

Thank you very much Imran.

 

Thank you very much Pradeep.

I used the same way.

I am able to use lookup icon for master detail relationship.

I am using this page to create new record of my cutom object. Its working fine.

I created new record of my custom object ACF_Contract__c using save command button.

 

I have 2 doubts.

1) where is that standard controller "ACF_Contract__c" for my custom object?

2) how to add custom code now for same visual force page to provide more functionality? (as i can't use controller(custom) and standard controller at the same time)

 

 

 

 

Imran MohammedImran Mohammed

Hi Sameer,

 

My answers inline,

 

1) where is that standard controller "ACF_Contract__c" for my custom object?

    Standard controller of ACF_Contract__c is internally mapped to the custom object. You need not create apex class for the standard controller.

2) how to add custom code now for same visual force page to provide more functionality? (as i can't use controller(custom) and standard controller at the same time)

You can create custom controllers that can be used as extensions in your visualforce page

For ex:

 <apex:page standardController="ACF_Contract__c" extensions="your custom controller">

The extension class should be like this,

Public class yourcustomclass

{

//constructor

public yourcustomclass(ApexPages.StandardController mycontroller)

{

//your code

}

 

}

You can find some examples in Apex guide.

sameer123sameer123

Hi,

Thank you Imran.

It is really helpful.

 

Thank you very much :)

sameer123sameer123

Hi,

 

I am using save button of standard controller of my custom object "ACF_Contract__c" as above.

But after new record is created onclick of save its taking me to the newly created record page.

I want to insert record of my custom object on save and remain on same page where i accept details of my custom object.

What should i do?

Imran MohammedImran Mohammed

Use rerender attribute to remain on the same page.

ViwalViwal

@Pradeep,

I am developing a custom search page for records.

I am using it there to create a look up.

How can we fetch this value in the controller so that I can add this to soql?