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
Dana ClarkDana Clark 

I have a custom "New" button on the asset object that auto populates a field. However, if the user selects the "Cancel" button they receive an error message. How do I correct this?

Here is the code on the custom "New" button:
https://vitl.my.salesforce.com/02i/e?retURL=%00bd0000000j1wB&acc_id={!Account.Id}&Name="Do Not Edit - will auto populate"

Here is the error message the user receives if they then select the "Cancel" button:

URL No Longer Exists
You have attempted to reach a URL that no longer exists on salesforce.com. 

You may have reached this page after clicking on a direct link into the application. This direct link might be: 
• A bookmark to a particular page, such as a report or view 
• A link to a particular page in the Custom Links section of your Home Tab, or a Custom Link 
• A link to a particular page in your email templates 

If you reached this page through a bookmark, you are probably trying to access something that has moved. Please update your bookmark. 

If you reached this page through any of the other direct links listed above, please notify your administrator to update the link. 

If you reached this page through a link on our site, please report the broken link directly to our Support Team and we will fix it promptly. Please indicate the page you were on when you clicked the link as well as any other related information. We apologize for the inconvenience. 

Thank you again for your patience and assistance. And thanks for using salesforce.com!
Best Answer chosen by Dana Clark
John TowersJohn Towers
Your retUrl parameter in the url should be "retURL=%2F00bd0000000j1wB". The %2F is an encoded '/'.

All Answers

John TowersJohn Towers
Your retUrl parameter in the url should be "retURL=%2F00bd0000000j1wB". The %2F is an encoded '/'.
This was selected as the best answer
Dana ClarkDana Clark
Thank you John.  That worked...sort of.  I no longer get the error and it now returns the user to the detail page of the custom button, which is the "00bd0000000j1wB", so I get that part.  If I wanted it to return back to the page from which it came, how should I code that?

For example, this button is to place an asset on an account.  If someone were to cancel out of it, how could I have it return to the detail page of the account they were on?  Since the "00bd0000000j1wB" of the retURL would vary, is there a different type of coding that should be used here?
John TowersJohn Towers
You can use the merge field for the Account Id to direct the user back to the Account record:  "retURL=%2F{!Account.Id}". 
Dana ClarkDana Clark
Of course I can!  Can you tell I'm new to this and trying to modify someone else's code?  Thanks so much for your help John.  This worked.