Tuesday, January 28, 2014

How to reset an APEX process

While I was setting up a demo the other day, I ran into the following issue: My main start page contains a list of customers and that list is created by a call to a (remote) web service. Due to the nature of this service, it takes a few seconds to get a result back - not very slow but slow enough to annoy me. So I looked at ways of caching the web service results as I noticed that in the process definition I could choose for either "Run every page visit" (default) or "Once per session or When reset". And I would like to reset the results when I entered a new customer - so it would show up after a new web service call. So the only thing I had to do is "reset the process". But wherever I looked - especially in the apex_util package - nothing that would do that trick. Searching the OTN Forum or old fashioned Googling neither added to a solution. A "cry for help" on Twitter resulted in a work around - "accidentally" the same one I had thought off: Add a copy of that process to that page and fire that on request only.
But after a day Patrick replied, unveiling there is an (undocumented) procedure apex_application.reset_page_process (with the internal Process ID as the parameter) or apex_application.reset_page_processes (with the Page ID as a parameter). So I tried the second one - because it's easier to figure out what page ID I need than the process ID - and that worked flawless.
So maybe you can use this more fine-grained caching mechanism in your application as well - but be warned: it's undocumented so it can change in a future version!
Another alternative solution would have been: enable caching of the page and programmatically reset it using the apex_util.clear_page_cache procedure.




Post a Comment