How to use the APEX Error Handling setting in FOEX

For FOEX forms and grids we provide developers the ability to perform AJAX validations. However it can be time consuming to write validations for every possible scenario to maintain data integrity, especially when the database may have these validations already in place in the form of constraints.

So what if we didn’t write any validations for our constraints? The issue with this approach is that the end user will see a pretty cryptic FOEX exception message, like the one below:

foex-grid-unhandled-exception

 

The good news is that this can be easily fixed since we have provided support within our code base to call the user-defined APEX Error Handling PLSQL function whenever an exception is raised within a FOEX plugin.

This error handling function provides the capability to edit these error messages before they are sent to the browser. Introduced back in APEX 4.1 this function can be defined either at the page and/or application level, with the page level taking precedence over the application level setting.

A good starting point to familiarize yourself with this functionality is to check Patrick Wolf’s blog post on the topic back in 2011, which includes some great example code to start with. Using the exact same approach which Patrick describes in the post you can transform this message into something much more readable.

 

foex-apex-error-handling-fn-app

 

Here I’ll add in the translated exception message for the FK_CTY_CTRY constraint error:

insert into CONSTRAINT_LOOKUP
  (CONSTRAINT_NAME, MESSAGE)
values
  ('FK_CTY_CTRY', 'You cannot delete the record as there are associated cities which exist!');

 

And this is the result after we implemented the new APEX Error Handling function:

foex-grid-translated-exception

 

We used this example to show how the FOEX Plugin Framework seamlessly integrates within APEX and can improve developer productivity.

Note: If you are looking for a solution on how to handle exceptions raised with a regular APEX “Execute PLSQL Code” dynamic action then please see the following forum entry.

Do you have a technical question about FOEX or want good tips for improving your application? We’ve launched this series of How To articles to help improve your FOEX applications even more.

Use #askFOEX on Twitter and we’ll get back to you as soon as possible or sign up for a free trial and see why it is a great tool for developing large-scale web applications!

Add your comment

Your email address will not be published. Required fields are marked *