Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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
add comment

2 Answers 2

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:form>
        <apex:pageBlockSection>
            <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" />
                    </apex:inputField>                                      
                </apex:actionRegion>
            </apex:pageBlockSectionItem>
        </apex:pageBlockSection>


        <!-- 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}"/>
            </apex:outputpanel>
        </apex:outputpanel>
    </apex:form>
    </apex:page>
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
add comment

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

http://bobbuzzard.blogspot.co.uk/2011/11/retrieve-related-object-fields.html

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
add comment

Your Answer

 
discard

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.