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
marcusaureliusmarcusaurelius 

Override Save() method

Does anyone have a good code sample of a Save() method that refreshes the vf page on itself?  OR can help me with my code below?

 

I have a vf form accessed via a sites page ...on save, i want to have the form insert the data and then refresh the newly created page.

 

I tried to do this via onclick action on the command:save ..but doesnt seem to work.

 

here is my current approach (not working)

 

<apex:commandButton action="{!save}" value="Calculate" onclick="back();"/>
 <script type="text/javascript">
function back()
{
window.parent.location.href='{!$Page.FAA_Compensation_Calculator}?id={!$CurrentPage.parameters.id}&txt={!$CurrentPage.parameters.txt}';
}
</script>

 

Tx!

Best Answer chosen by Admin (Salesforce Developers) 
prageethprageeth

Hello ;

Change your command button as below.

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

 Your controller should be as below.

public abstract class MyController{

Apexpages.StandardController controller;

public MyController(Apexpages.StandardController c){

controller = c;

}

 

public PageReference save() {

controller.save();//invoke standard Save method

return Apexpages.currentPage();//refresh current page

}

}

All Answers

SPDSPD

Since in the action attribute of commandbutton you are specifying "SAVE"...it works as the standard salesforce save.....

 

To overide use the following syntax : 

 

<apex:commandbutton value = "Save" action = "Save_Form"/>

 

you will need to create a funcion Save_Form in your apex controller and then write the logic inside this function....

 

 

here is a simple code...

 

 

public class mysample
{
    public string studentName
    {    get;set;    }
   
    public string studentClass
    {    get;set;    }
   
    public PageReference Save_Form()
    {
        Student__c objStudent = new Student__c();
        objStudent.Name = studentName;
        objStudent.Class__c = studentClass;
         insert objStudent;
       

        PageReference pr = new PageReference('/'+objStudent.Id);
        pr.setRedirect(true);
        return pr;
    }
}

Message Edited by SPD on 03-19-2010 11:44 PM
ErikssonEriksson
It's simple to refresh the VF page on itself. The VF page will be refreshed automatically after the action. And if you want to add some javascript function after the action, you can use the "oncomplete" attribute for the commandButton.
prageethprageeth

Hello ;

Change your command button as below.

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

 Your controller should be as below.

public abstract class MyController{

Apexpages.StandardController controller;

public MyController(Apexpages.StandardController c){

controller = c;

}

 

public PageReference save() {

controller.save();//invoke standard Save method

return Apexpages.currentPage();//refresh current page

}

}

This was selected as the best answer
Patrick DixonPatrick Dixon

How would I implement this for the Edit Page in the example blog application (see http://wiki.developerforce.com/index.php/Building_a_Blogging_Application_Using_Visualforce)?

 

The code provided doesn't seem to work because the oncomplete page redirect never happens.

 

 

[LINK now FIXED - I hate this BBS, has anyone at Dreamforce looked at vBulletin?]