0

I'm not trying to do anything really fancy. I just want a save button in a VF page with an extension to close the document after saving it. It doesn't necessarily have to go to a specific page. I would happy if it would just fall back to the view it was at like it would do with a typical save.

It's just a typical save button :

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

Thank you for any help !

6
  • what do you mean by close a document exactly? Is this a popup window? – Richard N Mar 12 '13 at 22:40
  • I just want it to act as though I saved a new Account or any other record. It should just save and go back to where it was when I hit the "New" button. In this case it's just at the default page for the tab. But I didn't think I would have to actually specify that. Thank you. – user2428 Mar 12 '13 at 22:43
  • What sort of document is that? And what exactly do you mean by "close the document" and "fall back to the view it was". Can you provide some more details? Is this a standard button page override? – Boris Bachovski Mar 12 '13 at 22:43
  • I'm sorry - I shouldn't have used the word "document". I'm just creating a new record with an object. I'd like to just hit a Save button and have it go back to the view I was in when I hit the New button. – user2428 Mar 12 '13 at 22:44
  • Do you want to override the standard New button with your custom VF page or you have a custom New button? – Boris Bachovski Mar 12 '13 at 22:49
3

There are 2 things 1) returl 2) saveurl

that you need to work on when you need to redirect on save use saveurl and on cancel use returl

check this post for more info on URLFOR function and how params can be added to the URLFOR

http://salesforcesource.blogspot.com/2008/12/urlfor-function-finally-explained.html

<apex:commandLink value="New" action="{!URLFOR($Action.account.new,'',[retURL="/apex/my_custom_page",saveURL="/apex/my_custom_page"])}" />

when the user clicks on the new button the account's new page is opened on save the user is redirected to the custom VF page.

3
  • Happy I could help !!! – Rao Mar 12 '13 at 23:17
  • rao - I may have confused you on this. I don't actually want the page to open and then automatically close. I just want the Save button to take the users to the URL. I think that code you showed would do a New and then a Save ? I dunno - it's the first time I've used URLFOr or retURL. Thanks again ! – user2428 Mar 12 '13 at 23:43
  • ah salesforce to what i know does not have access to save button in the action method. $action method has access to salesforce.com/us/developer/docs/pages/Content/…. – Rao Mar 12 '13 at 23:51
0

If you extend the StandardController, and manipulating the record the SC holds onto, you do something like this

ApexPages.StandardController ctl;
public MyController(ApexPages.StandardController ctl) {
    this.ctl=ctl;
}

and then you can call

return ctl.save();

and

return ctl.cancel();
3
  • jkraybill, So, that just goes into my controller ? I already have this in the controller : public Multi_Select_From_Field(ApexPages.StandardController controller) { Where should this go in accordance to that ? Where should this go ? : return ctl.save(); Should I just leave the regular commandbutton save line in the VF page ? Thanks for all of your help. I know I've got stupid questions. I'm very much a newbie. – user2428 Mar 13 '13 at 2:32
  • @jkraybill was just rethinking your approach !!! Why would you want to click save for the user!!! Rather how do you think its scalable? If there are required fields on the page you can URL encode the values and save the record, but this would not be an ideal solution in case there are multiple required fields to save/ dynamic values to be filled in for every field on save!! please clarify if i am missing soemthing – Rao Mar 13 '13 at 16:55
  • @rao calling ctl.save isn't "clicking save for the user" - you have a custom VF page that presumably has some editable fields, and a save button that calls your controller's save method. In this case, we return ctl.save() to make sure the PageReference return logic is exactly consistent with Salesforce standard controller logic. I don't really understand the rest of your comment. – jkraybill Mar 14 '13 at 2:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.