+ Start a Discussion
Todd B.Todd B. 

How to call two actions from one button on VF page?

I have been handed a fairly complex VF page to update.  The are several sections on the page, call updated by clicking on a row in a table.  The issue I am having is, when some updates one of the subsections on the page, I need the entire page to refresh.  Currently, I have a two button process, the first button is the standard "Save" functionality:
<apex:commandButton value="Save" action="{!saveTask}" status="loadSDMember" oncomplete="RefreshText();" rerender="taskDetail, SDMember,  SDMemberSummary, PhoneDetail,  debug" rendered="{!editTask}">

<apex:param name="editTask" value="false" assignTo="{!editTask}"/>
                                        
</apex:commandButton>
Then I created a second button to refresh the page
<apex:commandButton value="Press Here After Saving" action="{!getSDMember}" status="loadSDMember" oncomplete="RefreshText();" rerender="taskDetail, SDMember,  SDMemberSummary, PhoneDetail,  debug">
                                       
<apex:param name="taskID" value="{!task.id}" assignto="{!taskID}" />                                        <apex:param name="editMode" value="false" assignto="{!editMode}" />                                        <apex:param name="editTask" value="false" assignto="{!editTask}" />                                        <apex:param name="viewFullRecord" value="false" assignto="{!viewFullRecord}" />                            <apex:param name="SDMemberID" value="{!SDMember.id}" assignto="{!sObjectID}" />
<apex:param name="PHID" Value="" assignTo="{!sObjectid02}" />

</apex:commandButton>

Is it possible to combined this into just one button?
Raj VakatiRaj Vakati
I could say yes .. But can you share the controller method as well for getSDMember and saveTask actions 
Todd B.Todd B.
public  class CareCoachConsole_Controller {

    public integer page {get;set;}                    //store value of current page
    public decimal pages {get;set;}                   //store calculated number of pages
    public decimal itemsPerPage {get;set;}                 //number of Tasks shown per page
    public boolean editMode {get;set;}                //store boolean variable for making fields editable

    public SD_Member__c SDMember {get;set;}           //variable to store all SDMember data
    public List<Task> SDMemberOpenTasks {get;set;}    //list of all open taks on SDMember
    public List<Task> SDMemberClosedTasks {get;set;}  //list of closed tasks on SDMember
    public List<Phone_Numbers__c> SDMemberPhoneNumbers {get;set;}  //list of SDMember Phone Numbers from the Phone_Numbers__c Object
    
    public string sObjectName = 'SD_Member__c';       //string specifying object name for use in dynamic query
    public string sObjectFields {get;set;}            //string that will hold csv of all fields on SDMember
    public string sObjectID {get;set;}                //parameter which will be assigned from visualforce page and used to query SDMember with the given ID
    public string sObjectSOQL {get;set;}              //string of the complete SOQL query that returns all fields on SDMember
    
    
    public string sObjectName01 = 'Task';       //string specifying object name for use in dynamic query
    public string sObjectFields01 {get;set;}            //string that will hold csv of all fields on SDMember
    public string sObjectID01 {get;set;}                //parameter which will be assigned from visualforce page and used to query SDMember with the given ID
    public string sObjectSOQL01 {get;set;}              //string of the complete SOQL query that returns all fields on SDMember


    public Task task {get;set;}
    public id taskID {get;set;}                        //task id from SOQL query
    public boolean editTask {get;set;}                //store boolean variable for making fields editable
    
    public List<Task> openTasks {get;set;}            //list of current users open tasks
    public Integer openTasksCount {get;set;}
    public string taskSOQL {get;set;}                 //string of SOQL query that returns current ussers tasks related to SDMember
    public string sortDir {                           // the current sort direction. defaults to asc
        get  { if (sortDir == null) {  sortDir = 'asc'; } return sortDir;  }
        set;
    }
    public string sortField {                        // the current field to sort by. defaults to ActivityDate
        get  { if (sortField == null) {sortField = 'ActivityDate'; } return sortField;  }
        set;
    }
    
    public CareCoachConsole_Controller() {
        editMode = false;                            //edit off by default
        editTask = false;
        page = 0;                                    //start at page 0
        openTasksCount = 0;
        itemsPerPage = 10;
        runQuery();                                  //run query to get current users tasks
        sObjectFields = '';                          //initialize as an emply string to prevent 'null field__c, ...'
        //get the object then get the fields and then field names (returns a list and itterates through it)
        for(string field : schema.getglobaldescribe().get(sObjectName).getdescribe().fields.getmap().keyset()){
            sObjectFields += field + ', ';           //build string of all fields on the given sObject
        }
        sObjectFields = sObjectFields.substring(0,sObjectFields.length()-2);    //remove the trailing comma
        sObjectFields+=', lastmodifiedby.name';

 // added 02/17/17 to Pull all the Task Related Fields       
        sObjectFields01 = '';                          //initialize as an emply string to prevent 'null field__c, ...'
        //get the object then get the fields and then field names (returns a list and itterates through it)
        for(string field : schema.getglobaldescribe().get(sObjectName01).getdescribe().fields.getmap().keyset()){
            sObjectFields01 += field + ', ';           //build string of all fields on the given sObject
        }
        sObjectFields01 = sObjectFields01.substring(0,sObjectFields01.length()-2);    //remove the trailing comma
        sObjectFields01+=', lastmodifiedby.name';
    }
    
    public void toggleSort() {
        // simply toggle the direction
        sortDir = sortDir.equals('asc') ? 'desc' : 'asc';
        // run the query again
        runQuery();
    }
    
    public void runQuery() {
          openTasksCount = [select Count() from Task Where OwnerId = :UserInfo.getUserId() and what.type = :sObjectName and IsClosed = False];
          pages = (openTasksCount/itemsPerPage).round(roundingMode.UP);
          taskSOQL = 'select subject, Status, Priority, ActivityDate, Population_Type__c, whatid, what.name, category__c, SD_Member_Time_Zone__c, id from Task Where OwnerId = \''+ UserInfo.getUserId() +'\' and IsClosed = False and what.type = \''+ sObjectName +'\' order by ' + sortField + ' ' + sortDir + ' limit '+ itemsPerPage +' offset '+ page*itemsPerPage;
          //used for testing since all records are assigned to Todd
          /*
          openTasksCount = [select Count() from Task Where OwnerId = '005i0000002W0gt' and what.type = :sObjectName and IsClosed = False];
          pages = (openTasksCount/itemsPerPage).round(roundingMode.UP);
          taskSOQL = 'select subject, Status, Priority, ActivityDate, whatid, what.name, id from Task Where OwnerId = \'005i0000002W0gt\' and IsClosed = False and what.type = \''+ sObjectName +'\' order by ' + sortField + ' ' + sortDir + ' limit '+ itemsPerPage +' offset '+ page*itemsPerPage;
          */
          openTasks = Database.query(taskSOQL);
    }
    
    public void nextPage(){
        page+=1;        //change offset of the query (go to next page)
        runQuery();     //run query to return the next set of tasks
    }
    
    public void prevPage(){
        page-=1;       //change offset of the query (go to previous page)
        runQuery();    //run query to return the previous set of tasks
    }
    
    public void getSDMember(){
        getTask();
        sObjectSOQL = 'select ' + sObjectFields + ' from ' + sObjectName + ' where id = \'' + sObjectID +'\'';    //build complete query statement for SDMember which includes all the fields for easy reference
        SDMember = Database.query(sObjectSOQL);                                                                   //run query using dynamically build SOQL obove
        getSDMemberOpenTasks();
        getSDMemberClosedTasks();
        getSDMemberPhoneNumbers();
    }
    
    public void getSDMemberOpenTasks(){
        SDMemberOpenTasks = [select Subject, Status, Priority, ActivityDate, whatid, Population_Type__c, Category__c,id                           //query open tasks related to this SDMember
                             from Task
                             where whatid = :sObjectID and isClosed = false];    
    }
    
    public void getSDMemberClosedTasks(){
        SDMemberClosedTasks =  [select Subject, Status, Priority, ActivityDate, whatid, id, LastModifiedDate      //return closed tasks related to this SDMember
                                from Task
                                where whatid = :sObjectID and isClosed = true
                                order by ActivityDate desc
                                limit 5];
    }
// Added on 03/13/2018 Pulls all of the SD Members Active Phone Numbers from the Phone_Numbers__c object.
    public void getSDMemberPhoneNumbers(){
        SDMemberPhoneNumbers = [SELECT PhoneCTD__c,Phone_Number_Status__c,Phone_Type__c 
                                FROM Phone_Numbers__c 
                                WHERE Use_Me__c = True and SD_Member_Link__c = :sObjectID];                         
                             
                              // where whatid = :sObjectID and isClosed = false];    
    }    
    public void save(){
        update SDMember;        //save any updates to selected SDMember record
        getSDMember();
    }
    
    public void newTask(){      // create shell for new task
        task = new Task();      // prepopulate some information
        task.whatid = sObjectID;
        task.OwnerId = UserInfo.getUserId();
    }
    
    public void getTask(){      // retrieve selected task
//        List<Task> t = [select subject, Status, Priority, ActivityDate, whatid, Description, Population_Type__c, Category__c, OwnerId from Task Where id = :taskID];
//        if(t.size() > 0)
//            task = t[0];


        sObjectSOQL01 = 'select ' + sObjectFields01 + ' from ' + sObjectName01 + ' where id = \'' + TaskID +'\'';    //build complete query statement for SDMember which includes all the fields for easy reference
        Task = Database.query(sObjectSOQL01);             
    }
    
    public void saveTask(){
        if(task.id == null)         // if new task then insert
            insert task;
        else
            update task;            // otherwise update task
        getSDMemberOpenTasks();     // get current data
        getSDMemberClosedTasks();
        runQuery();
    }