I Have a custom object called Withdrawal which is having a lookup to Opportunity object My requirement is to override the standard New creation button for the Withdrawal object and whenever someone selects a opportunity via the lookup in the Withdrawal object it should autopopulate the rest of the fields. For example: I have a student_id__c field in my opportunity as well as withdrawal object both Now at the time of record creation when I am selecting an opportunity from the lookup which has a student Id already present, it should automatically populate the student id of that opportunity in the withdrwrawal new record creation form. I am struggling hard to create something using VF page,but the prepopulation of fields is not coming up on display,please also suggest if the same can be done in lightning as well would be most helpful
<apex:page standardController="Withdrawal__c" extensions="WithdrawalExtension">
<apex:form id="theFrm">
<apex:inputField id="Opportunity" value="{!Withdrawal__c.Opportunity_Contact__c}">
<apex:actionSupport event="onchange" action="{!OppSelected}" rerender="theFrm"/>
</apex:inputField>
<apex:inputText id="studentId" value="{!Withdrawal__c.Opportunity_Contact__r.Student_ID__c}" />
</apex:form></apex:page>
public class WithdrawalExtension {
private ApexPages.StandardController internalCon;
public WithdrawalExtension(ApexPages.StandardController con){
internalCon = con;
}
public void OppSelected(){
Withdrawal__c sa = (Withdrawal__c)internalCon.getRecord();
Opportunity Opp = [Select Id, Student_ID__c From Opportunity where Id = :sa.Opportunity_Contact__c];
sa.Opportunity_Contact__c = Opp.Id;
}
}
In a nutshell if I say it with an image
2)The student Id associated with that opportunity must be showing up in the same form itself auto-populated and auto-displayed in the same form.similarly when we change the selected Opportunity it should automatically update the value of the other fields accordingly