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
David GiffordDavid Gifford 

Looking to save selected account records in list using "ONCOMPLETE" command in apex:commandbutton

Very straight forward listview table of account records - see apex:pageblocktable below


Within this account listview table, we have a checkbox field at the account object as shown in our listview. The user can check this box in the account listview apex:inputField value="{!a.Worked__c}" .


I need to save these checked Account Records when the user clicks on the apex:commandbutton to move as shown in the action="{!first}" or "{!previous}" call button selected.


I need to save the selected apex:inputField value="{!a.Worked__c}" / using the "ONCOMPLETE" attribute in the apex:commandbutton



apex:commandbutton action="{!first}" value="First Group" ONCOMPLETE="{!xxSaveSelectedRecordsxx}" apex:commandbutton


Example ListView Table of Account Records:

apex:pageBlockTable id="AccountList" value="{!Accounts}" var="a"

apex:column value="{!a.Id}"/

apex:column value="{!a.Name}"/

apex:column headerValue="Worked?"> apex:inputField value="{!a.Worked__c}" / /apex:column>

apex:column value="{!a.Phone}"/> /apex:pageBlockTable>


Example Nav Buttons:

apex:commandbutton action="{!first}" value="First Group" /apex:commandbutton

apex:commandbutton action="{!previous}" value=" Previous Group" rendered="{!hasPrevious}">/apex:commandbutton apex:commandbutton action="{!next}" value="Next Group >" rendered="{!hasNext}">/apex:commandbutton>

apex:commandbutton action="{!last}" value="Last Group">/apex:commandbutton>


ONCOMPLETE String - The JavaScript invoked when the result of an AJAX update request completes on the client.


Thanks for your help....

Puneet SardanaPuneet Sardana



What you need is to call an Javascript function on oncomplete. Then in that javascript function call a controller method to save the records (via action function). Or you can use action support like


           <apex:commandButton action="{!first}" value="First Group">
<apex:actionSupport event="oncomplete" action="{!saveredords}" rerender="test" status="refreshstatus"/>
David GiffordDavid Gifford

thanks for your input here Puneet,


I really like your "apex:actionsupport" example. I would be confident this is the solution I am looking for.....


At this time in my SF developer journey, I have no idea on how to write this controller method. 

We are currently using a controller to limit the number of records within the ListView.

Can you point me in the right direction on writing the controller method to save the modified Account records within the ListView (via action function). 


Again, thank you very much for you help........


I just tested this but it does not work..... just trying to keep it simple....


<apex:commandbutton action="{!next}" value="Next Group >" rendered="{!hasNext}" >
<apex:actionSupport event="onclickedbutton" action="{!save}" /> </apex:commandbutton>











Puneet SardanaPuneet Sardana

Hi David,


<apex:commandbutton action="{!next}" value="Next Group >" rendered="{!hasNext}" >
<apex:actionSupport event="oncomplete" action="{!save}" />



And the controller method will be


public PageReference save()


        update YourAccountList;



Can you post your code then I can help by changing that. Please post the page and controller.

David GiffordDavid Gifford

Puneet, again thank you for your help


In my controller, I do not know how to identify my “AccountList”

Here is more detail….

Somewhere here is the answer…. I just am not sure where

I am not sure about the public void doNothing() { }, can it be removed?


Current Controller Working to limit records in page set size

public class SuperNav2{


   public SuperNav2(ApexPages.StandardSetController accountcontroller) {




      public void doNothing() { }



Current Record Selection Using “SelectList”


                <apex:panelGrid columns="14">

                    <apex:outputLabel value="Select List to Work: " for="SFSNviewsLists" />

                    <apex:selectList id="SFSNviewsLists"  value="{!filterId}" size="1"    >

                        <apex:actionSupport event="onchange" rerender="account_table"   />

                        <apex:selectOptions value="{!listviewoptions}"   />                         



Current pageBlockTable


<apex:pageBlockTable value="{!SFSNaccounts}" var="accSFSN" id="account_table"   >


<apex:column value="{!}"/>  


<apex:column headerValue="Worked?">

                    <apex:inputcheckbox value="{!accSFSN.Worked__c}"   />        




  <apex:column headerValue="Last Updated">

                    <apex:outputField value="{!accSFSN.lastmodifieddate}"/>         



                <apex:column value="{!}" /> 

                <apex:column value="{!accSFSN.type}"/>  


                <apex:column value="{!}"  />             



Puneet SardanaPuneet Sardana

I guess you account list is SFSNaccounts the one you are using in value of pageblocktable. But where is this defined in controller? The code looks quite messy. Can you pm me what you want to achieve?

David GiffordDavid Gifford

Thanks again for your help, we will get there……


Updated one line in Controller in BOLD with my best effort at defining “SFSNaccounts”


public class SuperNav2{

   public SuperNav2(ApexPages.StandardSetController accountcontroller) {




    public List<Account> SFSNaccounts;    


    public PageReference save()


        update SFSNaccounts;    

        return null;


      public void doNothing() { }




When I check the checkbox for Worked in the pageblocktable row and click the save button we get…..




Visualforce Error

System.VisualforceException: Modified rows exist in the records collection!