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
Ken AKen A 

Overriding Save button

Does anyone know how to override the "save" button for custom objects? I want to go to another SF webpage after completing a object insert. The only override I see is the "Accept" button, but it doesn't appear to be the "Save" button. Perhaps this is not possible because then it wouldn't be possible to insert the record into the DB.
So if this is the case does anyone know how to accomplish this:
I have two tables
Orders
Order Items
 
User adds an item: Currently when the item page "save" is it it goes to the completed item...instead I want to have it go back to the "Orders" page.
 
Any help with be much appreciated.
HardhatHardhat
You can't override the save button itself.  What you can do is override the edit button to go to the same page you'd normally go to, but then set the saveURL parameter so that when the user presses save he's redirected to the page of your choice.  So the override should take the page to (let's say it's from a case):

/{!Case.Id}/e?saveURL=%2FsomeOtherObject

The saveURL has to be url encoded (hence the %2F I put in there).  This one obviously won't go anywhere, it's just an example.
finalistfinalist
What if the Case (in this example) doesn't exist yet? Is there a way to override the New button in a way that incorporates the saveURL parameter?

At the moment, I don't see how it could, particularly if the Case has required fields. I was thinking of including a function that creates a new Case, and then passes that Id along so that your syntax would end up looking more like:

(imagine code here to create a var newCaseId, create a new SObject Case, and then assign the resulting Id to newCaseId

/{!newCaseId}/e?saveURL=%2FsomeOtherLocation

But if there are required fields, then the new Case wouldn't be created until we added default values (or inserted temporary ones) that would have to be changed on the Edit page.

Please correct me if I'm wrong, and thanks!
werewolfwerewolf
Yes, you can definitely do that, by overriding the New button.  Just make sure the URL you override to has nooverride=1 in the URL also so that it doesn't get re-overridden and go into an infinite loop.
werewolfwerewolf
And anyway, it doesn't actually navigate to the saveURL until the values on the page have passed validation, so that's not an issue.
Kirk F.ax361Kirk F.ax361
I like hardhat's idea to override the new button.  However, this may not work in some situations.  If the object is created in some way that avoids this custom-created "new" button (for example, through an API, or through web-to-case, etc), then your custom logic won't be applied.

A trigger can help you here.  Have the trigger fire ON INSERT on the case object.  It can return error messages to the user's screen (so they can fix whatever's missing and save again), as well as perform lots of other tasks.

So, override the new button to get started.  But don't be surprised if some cases appear in your system which never called your special code!  I think only a trigger will ensure that your logic will be applied, no matter how the case is created.


Message Edited by Kirk F on 01-12-2009 11:51 AM
Ram-Clear-PostsRam-Clear-Posts

Hi Could plz send me ,an example for saveURL and tell me how its redirecting to another url ?

 

thanks in advance

werewolfwerewolf

Search "saveurl" in the search box at the top of these forums, you'll find tons of examples.