I have an <apex:form>
that gathers user input for various fields on the recipient__c
object and a custom controller that inserts the new record. Further in the controller I have another object scholarship_award__c
where I set the value of child fields of recipient__c
to be the same value that the user inputs.
When I save the record in the VF page, it only inserts the child fields I set and not the rest of the user inputted values.
Controller
public with sharing class regularController {
public Scholarship_Award__c sch {get;set;}
public Recipient__c rec {get;set;}
//Constructor
public regularController(){
sch = new Scholarship_Award__c(recipient__c=rec.Id);
rec = new Recipient__c(School__c=sch.School__c);
}
public void saveScholarship(){
rec = new recipient__c(School__c=sch.School__c);
insert rec;
sch.Recipient__c = rec.Id;
insert sch;
sch = new scholarship_award__c(recipient__c=rec.Id);
}
}
VF Page
<apex:page controller="regularController" extensions="testController" lightningStylesheets="true">
<apex:form>
<apex:pageBlock >
<!--Recipient form-->
<apex:pageBlockSection title="Add recipients" columns="2">
<apex:inputField value="{!rec.Name}"/>
<apex:inputField value="{!rec.Last_Name__c}"/>
<apex:inputField value="{!rec.Preferred_Name__c}"/>
<apex:inputField value="{!rec.Email__c}"/>
<apex:inputField value="{!sch.Award__c}"/>
<apex:inputField value="{!sch.School__c}"/>
<apex:inputField value="{!rec.School__c}" rendered="false"/>
<apex:inputField value="{!sch.Year__c}"/>
<apex:inputField value="{!rec.Specialty__c}"/>
</apex:pageBlockSection>
<apex:pageBlockSection title="Biography">
<apex:outputLabel >Upload or enter student biography/CV</apex:outputLabel>
<apex:inputFile id="myFile" value="{!myDoc.Body}" fileName="{!myDoc.Name}">
</apex:inputFile>
<apex:inputTextarea value="{!rec.Biography__c}" rows="3" cols="100"/>
</apex:pageBlockSection>
<!--Record list-->
<!--Submit all records in record list-->
<apex:pageBlockButtons location="bottom">
<apex:commandButton action="{!saveScholarship}" value="Submit"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
Where only
<apex:inputField value="{!rec.School__c}" rendered="false"/>
<apex:inputField value="{!sch.Year__c}"/>
<apex:inputField value="{!sch.Award__c}"/>
Are saving in the record in the related list and none of the other recipient fields are populated with the user inputted info.
Why might this be?