Is it possible to re-direct a user to a specific page based upon a value in a picklist field upon Edit? For example, if my user Edits a Case, and that case has a value of "yyy" in picklist field 1, I want the user to be re-directed to /apex/NewEdit, otherwise they should just stay on the standard edit page. However, I also only want this to apply when they click an Edit button, not a View or New button. I was thinking I could do this with an embedded Visualforce page containing a Javascript script, but I'm not quite sure how to accomplish it. This is what I started:

<apex:page standardController="Case">
    <apex:includeScript value="/soap/ajax/34.0/connection.js" />
    <script type="text/javascript">
        var NewEdit = new Object();

        NewEdit.openWizard = function(){
                "{!Case.RecordType.Name}" === "Account Services" &&
                "Some code here where URL contains e?', I think? But I'm not sure how to code that" 

            return this;




1 Answer 1


You can just use the action attribute to perform a server-side redirect by overriding the Edit button:

<apex:page standardController="Case" action="{!IF($RecordType.Name == 'Account Services', URLFOR($Action.Case.Edit, Case.Id, null, true), URLFOR($Page.NewVFPage, Case.Id, [id=Case.Id])}">

The "true" parameter in URLFOR sets the "nooverride" parameter, which will go to the correct "/e" URL for you. This will load marginally faster than using your own JavaScript, and should be forward-compatible with new technology, such as the Lightning Experience.

  • Thanks. The issue is that I cannot override the Edit button. Doing that disables inline editing, which I absolutely need for other Case record types. What I am trying to accomplish with JavaScript is to only override the Edit button for this specific record type and maintain the inline editing for others.
    – J. Neilan
    Commented Jun 6, 2016 at 18:16
  • @J.Neilan The solution to this problem is to override the View link with a page that looks like this: <apex:page standardController="Case"><apex:detail inlineEdit="true" relatedList="true" /></apex:page>. You can't reliably put code on an Edit page, nor anywhere in the standard user interface, nor write code that would alter the standard user interface in unapproved ways. You will either need both pages, accept the loss of inline editing, or just give up. Also, you might want to vote on this idea.
    – sfdcfox
    Commented Jun 6, 2016 at 18:23
  • Thanks. I do already have that option and it works well. I've also already voted for that idea ;-) The last piece I am trying to solve with the JavaScript was when a user clicks Edit in the Case related list, but I obviously cannot override the edit button to accomplish this because then it disables the inline editing. Do you know of any other way?
    – J. Neilan
    Commented Jun 6, 2016 at 18:39
  • @J.Neilan The page override I described is the only way I can think of that's still allowed by salesforce. Everything else from click-jacking to script injection to sidebar hacks are all gone. All we have left is approved configurations (such as overriding buttons), and chrome hacks (e.g. GreaseMonkey).
    – sfdcfox
    Commented Jun 6, 2016 at 18:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .