May 12, 2014

How to auto populate lookup field values to other fields in Salesforce?

Sample Code:

Visualforce page:

<apex:page sidebar="false" controller="SampleController" >
<apex:form >
    <apex:pageBlock id="pg">
        <apex:pageBlockSection columns="1">
            <apex:inputField value="{!interest.Name}"/>
            <apex:inputField value="{!interest.Member__c}">
                <apex:actionSupport event="onchange" action="{!fetchMemberDetails}" reRender="pg"/>
            <apex:inputField value="{!interest.Member_Name__c}"/>
        <apex:pageBlockButtons >
            <apex:commandButton value="Save"/>

Apex Controller:

public class SampleController {
    public Interest__c interest {get;set;}
    public Member__c member {get;set;}
    public SampleController(){
        interest = new Interest__c();
    public void fetchMemberDetails(){
        member = [SELECT Name FROM Member__c WHERE Id = : interest.Member__c];
        interest.Member_Name__c = member.Name;



No comments:

Post a Comment