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
KunlunKunlun 

How to set the text value in lookup field

Hi,

 

I would like to create a visual force page, which contains lookup fields.

 

And I would like to set some basic value in lookup field text box. So that user can click the "lookup" button to query with some basic condition.

 

For example:
<inputField value="a"/> (text field)
<inputField value="b"/> (lookup field)

 

User will set a value first, maybe "company", then I would like to copy the value of a ("company") to b's text box, so that I can query b with conditon of a ("company").

 

Any one can help me?

 

Thanks

Kunlun

sfdcfoxsfdcfox

You don't have access to b's text value in Apex Code, only its ID, if any. You could accomplish your task using JavaScript, if you were so inclined, however.

 

<apex:page standardController="Contact">
    <script>
    function updateAccountId(e) {
        var accountId = document.getElementById('{!$Component.form.accountId}');
        accountId.value = e.value;
    }
    </script>
    <apex:form id="form">
        <apex:inputText onchange="updateAccountId(this);" value="{!Contact.Description}"/>
        <apex:inputField id="accountId" value="{!Contact.AccountId}"/>
    </apex:form>
</apex:page>

Of course, change your values to suit, this is only for demonstration purposes. Note that you still can't access the text value of accountId in Apex Code, but if there is a reRender condition somewhere, the system would helpfully auto-fill with an ID value or a list of options if there are multiple choices.

Naveen NelavelliNaveen Nelavelli

one way solution is javascript..which is explained already another way is to use workflow to update b lookupfield...