2

I have an override on the "New" button for a custom object so that the name of a new record can be generated by a workflow rule from required fields in the object.

The override is a Visualforce page with the following code:

<apex:page standardController="Language_Locale__c"
    action="{!URLFOR($Action.Language_Locale__c.New, null, ['Name'='Do not enter'], true)}"
/>

Because the object has required fields, when I try to cancel the new record before filling in any data, I get an error message that required fields are missing.

How can I make the Cancel button simply cancel the new record operation?

1 Answer 1

2

I don't think it's the required fields that give you headache. I've overridden Account's "new" action in my dev org with similar code:

<apex:page standardController="Account"
    action="{!URLFOR($Action.Account.New, null, ['acc2'='Do not enter'], true)}"
/>

(by the way welcome to the site :) to format stuff as code use the icon that looks like {} or just indent the code block with 4 spaces)

Anyway, when I access that page I'm being redirected to

/001/e?
retURL=%2Fapex%2FaccNew%3FretURL%3D%252F001%252Fo%26save_new%3D1%26sfdc.override%3D1&
nooverride=1
&acc2=Do+not+enter

In absence of cancelURL SF will take whatever happened to be in the retURL. Meaning that you hit cancel, it dutifully navigates back to /apex/accNew, the redirect action fires and bounces you back...

So you have to specify the cancelURL yourself. It can be hardcoded /home/home.jsp, it can be object's tab... I could hardcode /001/o but bit better way would be to do this:

<apex:page standardController="Account"
    action="{!URLFOR($Action.Account.New, null, ['acc2'='Do not enter', 'cancelURL'=URLFOR($Action.Account.Tab,$ObjectType.Account)], true)}"
/>

It makes the URL look bit rubbish but it works :) And once you get the basics right you can dive into serious black magic:

<apex:page standardController="Account"
    action="{!URLFOR($Action.Account.New, null, [
        'acc2'='Do not enter', 
        'retURL'='', 
        'cancelURL'=URLFOR($Action.Account.Tab,$ObjectType.Account, ['retURL'=''])
    ], true)}"
/>

Quite a mouthful but if it outputs clean link I can live with that:

/001/e?
nooverride=1
&acc2=Do+not+enter
&cancelURL=%2F001%2Fo

You must log in to answer this question.

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