2

I'm trying to add an <apex:outputLink /> tag to a VF page and use the URLFOR() function to direct the user to create a new Case. I want it so that when they save or cancel on the new Case creation page they are redirected to the detail page of a custom object. My code is below.

<apex:outputLink value="{!URLFOR($Action.Case.NewCase, null, ['retURL'=URLFOR($Action.Custom_Object__c.View, 'a0A00000000IDID')], true)}" >Select</apex:outputLink>

My problem is that some users are first taken to the Record Type selection screen. Pressing cancel from this screen takes the User to my Custom Object detail page, but if they continue to the new Case screen and THEN hit cancel they are redirected to the VF page, or if they press save they are taken to the Case detail page. I've tried adding cancelURL and saveURL but they don't preserve through the Record Type selection screen.

How can I preserve the retURL through the Record Type selection screen? I must allow users to select a Record Type so hard coding this is not an option.

2

I focused on getting the Cancel action from new Sobject page to return to a page other than from whence I started. Apologies for not using Cases

  • Foo__c has record types
  • a09/e is the key prefix for Foo__c
  • ID is the ID of the record of the VF page where the outputLink exists - I used a standardController to test this; you could use something different here
  • someNonFooId represents your intent - go to a page other than where you came if user clicks Cancel on the new Foo__c page after selecting a recordtype. Your VF page should know what to put here.

Code

<apex:outputLink value="{!URLFOR($Action.Foo__c.New, null, 
                                 ['retURL'='/' & ID, 
                                  'save_new_url' = '/a09/e?retURL=/' & someNonFooId],
                                  true)}" >
    Create New Foo
</apex:outputLink>

The trick was to tell the record type selection page to use a provided parameter save_new_url as otherwise, the recordtype selection page will generate a save_new_url for itself with a retURL that goes back to whence it came (the page with the outputlink). Note the save_new_url parameter value contains a parameter retURL - this is what gets passed to the New Foo__c page and is used by the new Foo__c page's OOB cancel button. I probably could have made the value of save_new_url a URLFOR itself but ran out of time.

Of course, URL hacking the record type selection process is subject to SFDC change

  • Can you explain a little what save_new_url does exactly as I'm a little confused on its functionality. I tried your technique with a hard coded string and when I click the continue button it works. Like you mentioned though this is URL hacking which is frowned upon. This is why I am using URLFOR() instead of some sort of hard coded string. So I tried using URLFOR in the save_new_url and after hitting the continue button it takes me to the Record Type selection screen again, then clicking continue for a second time takes me to the new Case screen. – dBeltowski Apr 28 '16 at 18:30
  • @DougB save_new_url is the URL to go to after the recordtype is selected. In your situation, that would be the new Case page. That URL can, of course, include params, in your situation, the retURL you want the new Case Cancel button to go to. – cropredy Apr 28 '16 at 18:35
  • You're certainly right, it is an extremely hacky solution. One would think the $Action.sObject.New would handle the retURL better in situations where you need to select Record Type. – dBeltowski Apr 28 '16 at 19:11

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.