You need to sign in to do that
Don't have an account?
Sain
AutoPopulate Parent Object fields on the basis of selecting of Look up on child in VisualForce Page
Hi,
I have requirment to auto populate parent object(Opporutnity) fields vales into child (Project__c) fields on the basis of selecting lookup field.
Please share the sample code.
VF Page:
<apex:page controller="autopopulateclass">
<apex:form >
<apex:pageblock >
<apex:pageBlockSection >
<apex:inputField value="{!pro.Name}"/>
</apex:pageBlockSection>
<apex:actionRegion >
<apex:pageBlockSection id="projectInfo" title="Information of Project">
<apex:inputField value="{!pro.Opportunity__c}">
<apex:actionSupport event="onchange" action="{!populateRelAccFields}" rerender="accountInfo"/>
</apex:inputField>
<!--<apex:outputField value="{!opp.Account.Phone}"/>
<apex:outputField value="{!opp.Account.Type}"/>-->
<apex:inputField value="{!pro.Mobile_No__c}"/>
<apex:inputField value="{!pro.Email__c}"/>
</apex:pageBlockSection>
</apex:actionRegion>
<apex:commandButton value="Cancel" action="{!cancel}"/>
<apex:commandButton value="Save" action="{!save}"/>
</apex:pageblock>
</apex:form>
</apex:page>
Controller:
public with sharing class autopopulateclass {
public project__c pro{get; set;}
public opportunity opp{get;set;}
public autopopulateclass(){
pro=new project__c();
opp=new opportunity();
}
public pagereference populateRelAccFields(){
if(null!=pro.opportunity__c){
project__c pro1=new project__c();
pro1.mobile_No__c=opp.mobile_No__c;
pro1.email__c=opp.email__c;
}
return null;
}
public void save(){}
public void cancel(){}
}
Thanks in advance
Sain
I have requirment to auto populate parent object(Opporutnity) fields vales into child (Project__c) fields on the basis of selecting lookup field.
Please share the sample code.
VF Page:
<apex:page controller="autopopulateclass">
<apex:form >
<apex:pageblock >
<apex:pageBlockSection >
<apex:inputField value="{!pro.Name}"/>
</apex:pageBlockSection>
<apex:actionRegion >
<apex:pageBlockSection id="projectInfo" title="Information of Project">
<apex:inputField value="{!pro.Opportunity__c}">
<apex:actionSupport event="onchange" action="{!populateRelAccFields}" rerender="accountInfo"/>
</apex:inputField>
<!--<apex:outputField value="{!opp.Account.Phone}"/>
<apex:outputField value="{!opp.Account.Type}"/>-->
<apex:inputField value="{!pro.Mobile_No__c}"/>
<apex:inputField value="{!pro.Email__c}"/>
</apex:pageBlockSection>
</apex:actionRegion>
<apex:commandButton value="Cancel" action="{!cancel}"/>
<apex:commandButton value="Save" action="{!save}"/>
</apex:pageblock>
</apex:form>
</apex:page>
Controller:
public with sharing class autopopulateclass {
public project__c pro{get; set;}
public opportunity opp{get;set;}
public autopopulateclass(){
pro=new project__c();
opp=new opportunity();
}
public pagereference populateRelAccFields(){
if(null!=pro.opportunity__c){
project__c pro1=new project__c();
pro1.mobile_No__c=opp.mobile_No__c;
pro1.email__c=opp.email__c;
}
return null;
}
public void save(){}
public void cancel(){}
}
Thanks in advance
Sain