+ Start a Discussion
megmooPDXmegmooPDX 

save button - refresh into edit mode after save

I have a VF page displaying as a component in a custom console. It allows the user to perform what I call "quick edits" for a few key fields. When the console is opened, those fields are displayed with the component in edit mode. If the users changes or adds to these fields, then clicks save, it does save the records as I want it to. However, instead of refreshing to display the VF page, it refreshes to display the page layout of the (custom) object into which the records were saved. 

For a visual example, the first screen shot is what I want the left side component to look like all the time (before a save and after a save).
console component (VF page) as I want it to be before and after a save


This is what the page looks like after a save - it displays the object's detail page in view mode. I want it to display my custom VF page which is the edit mode shown above. 

User-added image


Is this possible? Thanks in advance for any contributions!
Best Answer chosen by megmooPDX
Damien Phillippi033905702927186443Damien Phillippi033905702927186443
Gonzalo gave you a lot of help but the key you want to avoid is his final line 'return standardController.save()'.  That will make your code continue to do the exact thing you want to avoid.  Try something similar to:

<pre>
public class YourExtension
{
  private ApexPages.StandardController controller;
  public YourExtension(ApexPages.StandardController controller)
  {
    this.controller = controller;
  }

  public void save()
  {
    controller.save();
  }
}
</pre>

Alternatively your save method could be:

<pre>
public PageReference save()
{
  controller.save();
  return null;
}
</pre>

All Answers

Damien Phillippi033905702927186443Damien Phillippi033905702927186443
Are you using a standard controller for this?  If you are, you might need to change it to a controller extension.  All you will need to do on your extension is to override the save() method to tell it to remain on the current page instead of navigating where the default save() method takes you to.
megmooPDXmegmooPDX
Yes, I am using the StandardContoller and thought that might be the issue. I'm a newbie to apex. Are you able to provide sample code as to HOW I override the save method?
Gonzalo AbrunaGonzalo Abruna

As you said, you need to override Save method. To do so, create your own controller extension as it is explained here:

http://www.salesforce.com/us/developer/docs/pages/Content/pages_controller_extension.htm

You can either override it by declaring a PageReference save() method, or just by redirecting Save button to another custom method that you define in your extension class.

Example:

public PageReference save(){
  //to do here

  return standardController.save();
}

Damien Phillippi033905702927186443Damien Phillippi033905702927186443
Gonzalo gave you a lot of help but the key you want to avoid is his final line 'return standardController.save()'.  That will make your code continue to do the exact thing you want to avoid.  Try something similar to:

<pre>
public class YourExtension
{
  private ApexPages.StandardController controller;
  public YourExtension(ApexPages.StandardController controller)
  {
    this.controller = controller;
  }

  public void save()
  {
    controller.save();
  }
}
</pre>

Alternatively your save method could be:

<pre>
public PageReference save()
{
  controller.save();
  return null;
}
</pre>
This was selected as the best answer
megmooPDXmegmooPDX
Thank you all for your help. 

d.phillippi1 - I implemented your code and it worked perfectly. Thanks!