+1 vote
by (163k points)

I have a custom controller that clears the form so that users can input another record in the list however it is requesting required fields be filled upon calling the saveAll method - even though there is no actions in the method other than return another page.

I suspect it is because I am creating new records at the end of the Add_row method:

        sch = new Scholarship_Award__c();
        rec = new Recipient__c();

Are there any workarounds? I need it to clear the form and submit existing inputted records without requesting required fields if the user has no more desired inputs.


        //Scholarship fields
        Scholarship_Award__c anotherScholarship = new Scholarship_Award__c();
        anotherScholarship.Award__c = sch.Award__c;
        anotherScholarship.Year__c = sch.Year__c;
        anotherScholarship.School__c = anotherRecipient.School__c;
        anotherScholarship.Recipient__c = anotherRecipient.Id;
        //Insert scholarshio
        upsert anotherScholarship;
        //Add to lists
        //Instantiate new record to clear form.  
        sch = new Scholarship_Award__c();
        rec = new Recipient__c();
        return null;

    //Insert everything
    public PageReference saveAll() {

    return page.awardsLanding;

VF Page

<apex:page controller="finalExperiment" lightningStyleSheets="true">

<!--Logo and header -->

<div style="text-align:center">
<!-- Logo as a static resource in setup > static resources -->
<apex:image url="{!URLFOR($Resource.FFE_Logo)}" height="109" width="655">

<!-- 1) Form for users to input scholarship info -->
<apex:form >
<apex:pageBlock title="Add Scholarships">
<!-- Add record button -->

<apex:pageBlockButtons location="bottom">
    <apex:commandButton value="Add Scholarship" action="{!add_record}"/>

<!-- Form starts -->
<apex:pageBlockSection title="Recipient" columns="2" id="recipient">
    <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="{!rec.School__c}" required="false"/>
    <apex:inputField value="{!rec.Specialty__c}"/>
    <apex:inputField value="{!sch.School__c}" rendered="false"/>
    <apex:inputField value="{!sch.Award__c}" required="false"/>
    <apex:inputField value="{!sch.Year__c}" required="false"/>


<!-- 2) A biography section where users can either upload documents or enter
student biography in a text rich area -->
<apex:pageBlockSection title="Recipient Biography">
    <apex:pageBlockSection columns="1">
       <div style="text-align:left">
     <apex:outputLabel >Upload or enter student biography/CV</apex:outputLabel>    
           <div style="text-align:right">
               <apex:inputFile id="myFile" value="{!myDocument.Body}" fileName="{!MyDocument.Name}">
       <apex:inputTextarea value="{!rec.Biography__c}" rows="3" cols="145"/>

<!-- 3) Table to display scholarships that users input -->

<apex:pageBlock >
<apex:pageBlockButtons location="bottom">
    <apex:commandbutton action="{!saveAll}" value="Submit All Scholarships"/>

    <apex:pageBlockSection columns="3" title="Your Added Recipients"> 
    <!--Recipient list left side -->
    <apex:pageBlockSectionItem > 
    <apex:pageBlockTable value="{!recList}" var="recipient" columnsWidth="">
        <apex:column headerValue="First Name" value="{!recipient.Name}"/>
        <apex:column headerValue="Last Name" value="{!recipient.Last_Name__c}"/>
        <apex:column headerValue="Preferred Name" value="{!recipient.Preferred_Name__c}"/>
        <apex:column headerValue="Specialty" value="{!recipient.Specialty__c}"/>
    <!--Scholarship list right side-->
    <apex:pageBlockSectionItem dataStyle="width:15%" labelStyle="width:23%">
    <apex:PageBlockTable value="{!schList}" var="scholarship" columnsWidth="30%,30%">
        <apex:column headerValue="Award" value="{!scholarship.Award__c}"/>
        <apex:column headerValue="Year" value="{!scholarship.Year__c}"/>
    <apex:PageBlockTable value="{!recList}" var="rec" columnsWidth="50%,50%">
        <apex:column headerValue="Email" value="{!rec.Email__c}"/>
        <apex:column headerValue="Biography" value="{!rec.Biography__c}" rowspan="2"/>

1 Answer

Welcome to Memory Exceeded, where you can ask questions and receive answers from other members of the community.
You can donate any amount for Orphans village using following QR Code.