function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Jeff JobsJeff Jobs 

Trying to create multiple records via VisualForce but screen not refreshing?

Goal is to enter info on an object, then enter different info on another object by creating multiple records.  So we have an update and multiple inserts.

I'm using buttons to go from from one page to the next and then I'd like a "Make Another" button to simply duplicate the second piece ad infinitum.  Here is what I have so far:

<apex:page standardController="SODA__c" extensions="PutbackExtension">
 
  <apex:sectionHeader title="Create Putback Work - Update SODA"/>
 
  <apex:form >
    <apex:pageBlock >
     
      <apex:pageBlockButtons location="bottom">
        <apex:commandButton action="{!cancel}" value="Cancel"/>
        <apex:commandButton action="{!save}" value="DONE"/>
        <apex:commandButton action="{!ToRST}" value="Create Resident Service Ticket"/>
      </apex:pageBlockButtons>
     
      <apex:pageBlockSection title="Enter Standard Putback Activity Amounts (If Applicable)" columns="1" collapsible="false">
        <apex:inputField value="{!SODA__c.House_Cleaning_Fee__c}" label="House Cleaning Fee"/>
        <apex:inputField value="{!SODA__c.Carpet_Cleaning_Fee__c}" label="Carpet Cleaning Fee"/>
        <apex:inputField value="{!SODA__c.Painting_Patching_Fee__c}" label="Painting/Patching Fee"/>
      </apex:pageBlockSection>
     
      <apex:pageBlockSection title="Enter Other Putback Activities and Amounts" columns="2" collapsible="false">
        <apex:inputField value="{!SODA__c.Other_Fee_1_Description_Long__c}" label="Other 1 Description"/>
        <apex:inputField value="{!SODA__c.Other_Fee_1__c}" label="Other 1 Fee"/>
        <apex:inputField value="{!SODA__c.Other_Fee_2_Description_Long__c}" label="Other 2 Description"/>
        <apex:inputField value="{!SODA__c.Other_Fee_2__c}" label="Other 2 Fee"/>
        <apex:inputField value="{!SODA__c.Other_Fee_3_Description_Long__c}" label="Other 3 Description"/>
        <apex:inputField value="{!SODA__c.Other_Fee_3__c}" label="Other 3 Fee"/>
        <apex:inputField value="{!SODA__c.Other_Fee_4_Description_Long__c}" label="Other 4 Description"/>
        <apex:inputField value="{!SODA__c.Other_Fee_4__c}" label="Other 4 Fee"/>
        <apex:inputField value="{!SODA__c.Other_Fee_5_Description_Long__c}" label="Other 5 Description"/>
        <apex:inputField value="{!SODA__c.Other_Fee_5__c}" label="Other 5 Fee"/>
      </apex:pageBlockSection>
     
    </apex:pageBlock> 
  </apex:form>
</apex:page>


(Second VF Page)
<apex:page standardController="Resident_Service_Tickets__c" extensions="PutbackExtension">
  <apex:sectionHeader title="Create Putback Work - New Resident Service Ticket"/>
  <apex:form >
    <apex:pageBlock >
   
      <apex:pageBlockButtons location="bottom">
        <apex:commandButton immediate="true" action="{!CancelRST}" value="Cancel"/>
        <apex:commandButton action="{!ToRST}" value="Make Another"/>
        <apex:commandButton action="{!save}" value="DONE"/>       
      </apex:pageBlockButtons>
     
      <apex:pageBlockSection title="Enter Putback Service Information" columns="1" collapsible="false">
        <apex:inputField value="{!Resident_Service_Tickets__c.Winning_Trade__c}" label="Trade" required="true"/>
        <apex:inputField value="{!Resident_Service_Tickets__c.Method_of_Payment_for_Trade__c}" label="Method of Payment" required="true"/>
        <apex:inputField value="{!Resident_Service_Tickets__c.Amount_Billed_to_MH__c}" label="Billing Amount" required="true"/>
        <apex:inputField value="{!Resident_Service_Tickets__c.Notes__c}" label="Work Done" required="true"/>
      </apex:pageBlockSection>
     
      <apex:pageBlockSection title="Object Relationships" columns="1" id="section1">
        <!-- <script>twistSection(document.getElementById("{!$Component.section1}").childNodes[0].childNodes[0]); </script> -->
        <apex:inputField value="{!Resident_Service_Tickets__c.Concierge__c}" label="Concierge"/>
        <apex:inputField value="{!Resident_Service_Tickets__c.Resident_Account__c}" label="Resident Account"/>
        <apex:inputField value="{!Resident_Service_Tickets__c.Resident_Opportunity__c}" label="Resident Opportunity"/>
        <apex:inputField value="{!Resident_Service_Tickets__c.Property__c}" label="Property"/>
        <apex:inputField value="{!Resident_Service_Tickets__c.Owner_Account__c}" label="Owner Account"/>
        <apex:inputField value="{!Resident_Service_Tickets__c.SODA__c}" label="SODA"/>
      </apex:pageBlockSection>
   
    </apex:pageBlock>
  </apex:form>
</apex:page>


(Extension Class)
public class PutbackExtension {

    //Declare Instance Variables
    private ApexPages.StandardController sc;
    private Id soda;
    private Id con;
    private Id roppId;
    private Opportunity ropp;
    private Id racc;
    private Id propId;
    private Property__c prop;
    private String putback;
    private Id acc;
   
    //Create Constructor
    public PutbackExtension(ApexPages.StandardController standardController) {
   
        sc = standardController;
       
        if(ApexPages.currentPage().getParameters().get('soda') == '123') {
       
            soda = ApexPages.currentPage().getParameters().get('id');
        }
       
        if(ApexPages.currentPage().getParameters().get('soda') != '123') {
       
            soda = ApexPages.currentPage().getParameters().get('soda');
        }   
       
        roppId = ApexPages.currentPage().getParameters().get('ropp');
        ropp = [SELECT Id, AccountId FROM Opportunity WHERE Id = :roppId];
        racc = ropp.AccountId;
        propId = ApexPages.currentPage().getParameters().get('prop');
        prop = [SELECT Id, Home_Sale_Opportunity__c, Concierge__c FROM Property__c WHERE Id = :propId];
        con = prop.Concierge__c;
        putback = 'PUTBACK';
        Opportunity opp =[SELECT Id, AccountId FROM Opportunity WHERE Id = :prop.Home_Sale_Opportunity__c];
        acc = opp.AccountId;
    }
   
    //Methods
    public PageReference ToRST() {
   
        sc.Save();
       
        Resident_Service_Tickets__c rstRecord = new Resident_Service_Tickets__c();
        rstRecord.Concierge__c = con;
        rstRecord.Resident_Account__c = racc;
        rstRecord.Resident_Opportunity__c = roppId;
        rstRecord.Owner_Account__c = acc;
        rstRecord.Property__c = propId;
        rstRecord.Troubleshooting_Notes__c = putback;
        rstRecord.SODA__c = soda;
        insert rstRecord;
       
        //rstRecord = (Resident_Service_Tickets__c)sc.getRecord();
       
        String soda = ApexPages.currentPage().getParameters().get('id');
        String ropp = ApexPages.currentPage().getParameters().get('ropp');
        String prop = ApexPages.currentPage().getParameters().get('prop');
        String con = ApexPages.currentPage().getParameters().get('con');
               
        PageReference rst = new PageReference('/apex/PutbackPage2?id='+rstRecord.Id+'&soda='+soda+'&ropp='+ropp+'&prop='+prop+'&con='+con+'&rst='+rstRecord.Id);
       
        return rst;
    }      
   
    public PageReference CancelRST() {
   
        String rst = ApexPages.currentPage().getParameters().get('rst');
       
        String soda = ApexPages.currentPage().getParameters().get('soda');
       
        delete [SELECT Id FROM Resident_Service_Tickets__c WHERE Id = :rst];
       
        PageReference start = new PageReference('/'+soda);
       
        return start;
    }
}

It works but when I go to make another Resident Service Ticket (when I push "Make Another") it still shows me the last one filled in as displayed below:

User-added image

I'm know I'm probably missing something with refreshing the standard controller but I'm really at a loss here.  Any help would be greatly apprecitated.  Thanks!
Best Answer chosen by Jeff Jobs
Jeff JobsJeff Jobs
turns out it was something simple:

I wasn't using .setRedirect(true) in my return statement.  Should've been:

return rst.setRedirect(true);

It was slightly more complicated to get it to do precisely what I wanted but my main stumbling block was the setRedirect being absent.