You need to sign in to do that
Don't have an account?

Autopopulate values on Lookup selection
Hi,
I have some textboxes in my VF page. And an Account lookup field.
I want to populate the textboxes with the value in Address field of the Account object which I am selecting via the Account lookup.
Regards,
Lakshmi.
Revisiting the post after quite long. Just thought of posting what I had done to solve the same at that time.
In the Visualforce page:
The lookup field:
<apex:inputField onchange="ChangeAccountInfo(this)" value="{!SL_Order__c.Opportunity__r.AccountId}"/>
JS function within <script></script> tag:
function ChangeAccountInfo(obj)
{
ChangeAccInfo();
}
Action function:
<apex:actionFunction name="ChangeAccInfo" action="{!ChangeAccInformation}" reRender="ShippingInfo,PageBlButton,pagemessage">
</apex:actionFunction>
Controller method:
public void ChangeAccInformation()
{
//Logic to fetch the address information based on the Account ID selected
.........
........
}
All Answers
Follow these:
VF PAGE: On your VF page where you have added Account lookup, add actionSupport. On change of Account lookup value this will call another method in your controller which will query the Account record slected and populate other fields that you want. Also this will rerender other fields on the page with the new values you have just queried
APEX CLASS:
I have typped the above code for your reference, it might have some typos etc. Use this for your refernce and add error handling etc.
IMP: If you have some required fields on the page, you might face some issues while rerendering and have to use actionregion tag here. To validate this functionlity, which you select an Account, fill all the required fields on the page firsy, if you have any,
Revisiting the post after quite long. Just thought of posting what I had done to solve the same at that time.
In the Visualforce page:
The lookup field:
<apex:inputField onchange="ChangeAccountInfo(this)" value="{!SL_Order__c.Opportunity__r.AccountId}"/>
JS function within <script></script> tag:
function ChangeAccountInfo(obj)
{
ChangeAccInfo();
}
Action function:
<apex:actionFunction name="ChangeAccInfo" action="{!ChangeAccInformation}" reRender="ShippingInfo,PageBlButton,pagemessage">
</apex:actionFunction>
Controller method:
public void ChangeAccInformation()
{
//Logic to fetch the address information based on the Account ID selected
.........
........
}