+ Start a Discussion

Custom button javascript for conditional redirect after save operation


Hey guys, I have a question about javascript and custom buttons.


Basically, on a standard layout (NOT visualforce), I need a custom Save button that will perform the standard save operation, but instead of redirecting, will display a prompt asking the user if they want to add a related record. If so, redirect to the create new page, otherwise, go to the regular detail page.


Can somebody point me in the right direction for how to get started on something like this? Any examples available?

I don't think you'll be able to do this on a standard page. You can't inject your behaviour in to the flow in that way. The redirect to the detail page is server side. You might be able to add the prompt via an onclick handler added from an htmlarea component on the sidebar, but once you allow the save to continue you are out of the picture.

I'm looking into using Javascript remoting.


Can you tell me if I can make calls to the current standard controller with the Ajax library?

Are you still talking about standard pages, or visualforce?
Standard pages.

I've seen a lot of examples of calling custom apex controller methods.

I'm trying to figure out if I can access anything in the current stanardcontroller. Perhaps there's a way to call the save method from JS?

If not I suppose I'll have to replace the whole standard layout with visualforce.
Standard pages don't have controllers. They are built using a different technology to Visualforce and there's no way to interact with the server side.

Take a look at the apex:detail component - that uses the standard page layout for the record and record type in question, but inside a VF page.
I'm up to speed on the apex stuff. I've been doing a buttload of that.

The AJAX library is a bit fuzzy for me, I'm still trying to figure out what I can and can't do with it.
Rahul SharmaRahul Sharma
AFAIK, We cannot add custom buttons in the edit screen.