Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a form which I attached as an image. My requirement is I have a field called shopname. For this I have created a lookup using a custom object. When the user clicks beside of the shopname lookup, he can able to select from the customer table. Now my requirement is when the field has been selected, The below of the filed I want display remaining fields like address and mobile details as soon as the shopname selected.

Also, I would like to access the selected lookup field's value from an Apex controller.

A code sample of how to do this would be helpful.

share|improve this question

You can use apex:actionRegion and apex:actionSupport component to complete your functionality.

I have given a code snippet of VF page blow as an example. It is not a running code.

Assumption -

        shopDetail = Custom object which has shop name and other field  
                    thats need to be rendered based on shop selection contains.
        shopName__c = shop name lookp field
        isShopNameSelected = A function which returns true if shop name is selected else false.

    <apex:page Controller="shopDetailController" >
            <apex:pageBlockSectionItem >
                <apex:outputLabel value="Shop Name" />
                <apex:actionRegion >
                    <apex:inputField id="financialAidLst shoName" required="true" value="{!shopDetail.shopName__c}" label="Shop Name">
                    <apex:actionSupport event="onchange" action="{!isShopNameSelected}" rerender="FinancialAidPanel shopDetailSection" />

        <!-- This section shows shop details and will rendered only if shop is selected -->
        <apex:outputpanel id="shopDetailSection">
            <apex:outputpanel rendered="{!isShopNameSelected}">
                <apex:inputField value="{!shopDetail.address}"/>
                <apex:inputField value="{!shopDetail.mobileNumber}"/>
share|improve this answer
To add an explanation to Pramods code, The value you would select for shopname would be available in shopDetail.shopName__c and in the method isShopNameSelected you can query the record to get the shop details using the id got in shopDetail.shopName__c – Prady Jan 2 '13 at 7:22

I wrote up a blog post on this a while back at:

This has example markup and code to capture the lookup for a related object into the controller and retrieve fields from this related object for use on the page.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.