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
acrozieracrozier 

Save records on current page

Hello,

 

I have a custom edit page for a custom object which is doing almost everything that I need it to do.  The final piece is to save all the records on the current page before returning a new value.  Currently when you click the New button the new row will be added but will not retain changes made to the other rows.  Both my Visualforce and Controller are below:

 

Controller

 

public with sharing class Incent {
public list<AIIncentive__c> Incents {get; set;}
public list<job__c> job {get; set;}
public id jobid;
public string Button {get; set;}
    public Incent(ApexPages.StandardController controller) {
     id incentId= apexpages.currentpage().getParameters().get('id');
        jobid=[select id, Job__c from AIIncentive__c where id=:incentId].Job__c;

        Incents = [Select QTY__c, Description__c,  Honoraria__c, Job__c, Deleted__c  From AIIncentive__c  where Job__c = :jobid]; 
        job = [SELECT Account__c FROM Job__c WHERE id= :jobid];    
        }
      
      
    public PageReference Button(){

     AIIncentive__c obj = new AIIncentive__c();
     
     obj.QTY__c = 0;
     obj.Description__c = '';
     obj.Honoraria__c = 0;
     obj.Job__c = jobid;


    insert obj;
    
    PageReference acctPage = ApexPages.currentpage();
    

      acctPage.setRedirect(true);



      return acctPage;
     
     }
    }

 

Visualforce

 

<apex:page standardController="AIIncentive__c" extensions="Incent">
    <apex:form >
     <apex:pageBlock title="Edit Incentives">
     
         <apex:commandButton value="Save & Return" action="{!save}"/> 
         <apex:commandButton value="New" action="{!Button}">
             <apex:actionSupport event="onclick" rerender="incenttable" status="refreshstatus"/>
             <apex:actionStatus id="refreshstatus" startstyle="color:green;" startText="Refreshing...."></apex:actionStatus>
         </apex:commandButton>
     <center> 
         <apex:dataTable value="{!job}" var="j" cellspacing="5">
             <apex:column >
                 <strong>Account:</strong> &nbsp; <apex:outputField value="{!j.Account__c}"/>
             </apex:column><br />
             <apex:column >
                 <strong>Job Number:</strong> &nbsp; <apex:outputField value="{!AIIncentive__c.Job__c}"/>
             </apex:column>
         </apex:datatable><br />
     </center>
         
                 
         <apex:pageblockTable value="{!Incents}" var="incent">
             <apex:column headerValue="QTY">
                 <apex:inputField value="{!incent.QTY__c}"/>
             </apex:column>
             <apex:column headerValue="Description">
                 <apex:inputField value="{!incent.Description__c}"/>
             </apex:column>
             <apex:column headerValue="Honoraria__c">
                 <apex:inputField value="{!incent.Honoraria__c}"/>
             </apex:column>
             <apex:column headerValue="Deleted">
                 <apex:inputField Value="{!incent.Deleted__c}"/>
             </apex:column>
         </apex:pageblockTable>
       
       
    </apex:pageBlock>
   </apex:form>
 
</apex:page>

 

WizradWizrad

The reason your new button is funky is because of your actionSupport on that command button.

 

First of all, you don't need that at all.  The command button has attributes to do everything that youre doing with the actionSupport.  

 

Second, the only reason this works at all is because what you're rerendering does not exist, and as a result the entire page is reloaded, and the query for the Incents catches the newly inserted object and loses all the changes data on the others.

acrozieracrozier

both the actionSupport and the lack of a set ID to rerender are just artifacts from me trying to get this to work.  Originally I had just set the ID on my pageblocktable and the rerender on my command button, but this did not work.  The only way I actually got the page to refresh with the new values was from this : PageReference acctPage = ApexPages.currentpage(); acctPage.setRedirect(true); return acctPage;  in my controller.  Does anyone know why reRender does not work properly for my table?