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
kaulsaksoftkaulsaksoft 

Showing a lookup in VisualForce Page

Hi Can we show a lookup relationship in a Visual Force Page.

 

 

Best Answer chosen by Admin (Salesforce Developers) 
sforce2009sforce2009

Yes. you can certainly achieve this.
Use standardController and "extensions". Put your custom controller in extensions. it will work as you desire
this is example
<apex:page standardController="CustomerFinancialDetail__c" extensions="CustomerFin"/>

you just have to change the constructor thats all.

 

Cheers

Message Edited by sforce2009 on 06-27-2009 10:25 AM

All Answers

amar joshiamar joshi

You can use <apex:inputfield> to get the same look and fill of your field whether it is picklist,date,lookup...

 

try bellow code u can get the idea

 

 

<apex:page standardController="Opportunity"> <apex:form> <apex:pageBlock title="Opportunity"> <apex:pageBlockSection> <apex:inputField value="{!opportunity.name}"/> <apex:inputField value="{!opportunity.type}"/> <apex:inputField value="{!opportunity.accountid}"/> <apex:inputField value="{!opportunity.StageName}"/> <apex:inputField value="{!opportunity.closedate}"/> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>

 also checkout the bellow link for visulaforce documentation

 

Visaulforce documentation 

 

 

kaulsaksoftkaulsaksoft

Hi Amar

 

thanx for the reply

 

But i wanted a lookup icon appearing on the Visualforce page which i did by the code below. 

 

<apex:page Controller="CustomerFinancialDetail__c">
<apex:form ><apex:inputField value="{!CustomerFinancialDetail__c.Customer_ID__c}"/>
</apex:form>

</apex:page>

 

 

But if the do the same with the custom controller i do not get the lookup icon on my VisualForce Page

 

<apex:page Controller="CustomerFin">
<apex:form ><apex:inputField value="{!t.First_Name__c}"/>
</apex:form>

</apex:page>

 

 

public class CustomerFin {
CustomerContactDetail__c sample;

    public CustomerContactDetail__c getT() {
   
    sample = [SELECT First_Name__c, Name FROM CustomerContactDetail__c limit 1];
        return sample;
    }

public void setT(CustomerContactDetail__c value) {    sample = value;}

 

If you could help me with this.

 

regards

niyali

 

metaforcemetaforce

I don't think they have a native component that provides lookup functionality in VF pages. You may have to write something of your own. This can be a combination of an apex:inputField and SF lookup Icon. Take a look:

 

 

<apex:inputField id="someId" />
<img src="/s.gif" class="lookupIcon" onblur="this.className='lookupIcon';" onfocus="this.className='lookupIconOn';" onmouseout="this.className='lookupIcon';" onmouseover="this.className='lookupIconOn';" onclick="ShowLookup('{!AnyPropertyFromController}');"/>

 

You can write JavaScript in your popup lookup page to send back the selected value to the parent opener page.

 

Regards

metaforce

----------------------------------------------------------------------------------------

Please mark this as the solution if it works and help the community.


 

sforce2009sforce2009

Yes. you can certainly achieve this.
Use standardController and "extensions". Put your custom controller in extensions. it will work as you desire
this is example
<apex:page standardController="CustomerFinancialDetail__c" extensions="CustomerFin"/>

you just have to change the constructor thats all.

 

Cheers

Message Edited by sforce2009 on 06-27-2009 10:25 AM
This was selected as the best answer
Edwin VijayEdwin Vijay

Try using First_Name__r in place of First_Name__c...

 

Not sure if this would work but in case... 

kaulsaksoftkaulsaksoft

Thanx for the solution it worked fine.

 

 

elyb527elyb527
Which solution worked?
kaulsaksoftkaulsaksoft
The solution which was given by sforce2009 where we use the Standard Controller and Put our custom controller in extensions. By this I was able to get the same Lookup icon for the CustomObject.
elyb527elyb527
I have it working beautifully except for the fact that the Picklists do not display when in the portal.  If I try it as a salesforce user it works.  Are you making available to portal users?
kaulsaksoftkaulsaksoft

No I am not making it available to portal users. I am currently using it as a Salesforce user for which it is working fine.

kprkpr
I have tried the sample provided in this thread using both custom controller and controller extension. Neither method worked. Can anyone tell me what other code they had to write to make it work?

Thanks,