Tip#3 Avoid success message on refresh page

Tip#3 Avoid success message on refresh page

In this short post, we will give a workaround to prevent the success message from being displayed every time the user refreshes the page.

Problem overview and demonstration

If you are using an old version of APEX, you probably have faced this problem before.

Suppose you have a process that does something when processing the page and shows a success message if it is successful.

When the user submits the page, the process is executed, and the success message will be presented after the page is loaded. If you take a look at the URL, you see that there is a parameter called success_msg which holds the message. This parameter displays the notification every time the user refreshes the page or presses F5.

If the user refreshes the page or presses F5, the success message will appear again and again.

Get rid of the parameter in the URL

One of the workarounds to prevent showing the success message every time the user refreshes the page is to get rid of the success_msg in the URL by using a JavaScript snippet.

In your APEX Workspace, navigate to the page where you have a process and add this code in the global function

function _removeParam(key, sourceURL) {
   var url = new URL(sourceURL);
   url.searchParams.delete(key);
   return url.toString();
}

Then in the same page add the following JavaScript code when page load

window.history.pushState(null, null, _removeParam("success_msg", window.location.href));

Now, try again to submit the page and refresh using F5, hopfeully you wont see the success message again :).

We also can add the code at the application level in the page template to use it in all pages, but this would be in another tip :).