+ Start a Discussion
DevSFDevSF 

Perform Multiple Actions On Save Button Click In Visualforce Page

Hi Friends,

I am Updating a  record using Visualforce page. When I enter all the data into  visualforce page, Here i need to perform 2 actions.

1) Save the record
2) Open a link


I tried it using page reference(), but struck at some point.


<apex:commandButton value="Save" action="{!Save}" /> 


Controller ::

public class rerender {
        public Account acc {get;set;}
    public rerender(ApexPages.StandardController controller) {
 
    }
    public PageReference save(){
       
        PageReference reRend = new PageReference('/apex/ThankYou');
        reRend.setRedirect(false);
        return reRend; 
    }

}


In this, i was unable to save the record, but was able to open the link.


How to achieve this...!
 
badibadi
try this,
 
public class rerender {
        public Account acc {get;set;}
        public ApexPages.StandardController sc
    public rerender(ApexPages.StandardController controller) {
        sc=controller;
    }
    public PageReference save(){
       sc.save(); 
        PageReference reRend = new PageReference('/apex/ThankYou');
        reRend.setRedirect(false);
        return reRend; 
    }

}

 
Nayana KNayana K
/// Assuming by save you mean update of account 
public class rerender {
        public Account acc {get;set;}
    public rerender(ApexPages.StandardController controller) {
         acc = (Account)stdController.getRecord();
    }
    public PageReference save(){
       
        update acc;
        PageReference reRend = new PageReference('/apex/ThankYou');
        reRend.setRedirect(false);
        return reRend; 
    }

}

 
DeveloperSudDeveloperSud
Hi ,
Yes we can create a custom button which can perform multiple action. I just tested it in dev console.
You are missing the DML statement here in the save method.Use Insert,Update or (insert and update both ) based on your requirement.
Please comment if you find this helpful.Thanks!!!.
public PageReference save(){
        Upsert acc;
        PageReference reRend = new PageReference('/apex/ThankYou');
        reRend.setRedirect(false);
        return reRend; 
    }