Forum Stats

  • 3,769,600 Users
  • 2,252,990 Discussions
  • 7,875,116 Comments

Discussions

Best way to persist data for multi-page forms - APEX 21.1

McRivers
McRivers Member Posts: 66 Red Ribbon
edited Sep 29, 2021 11:03AM in APEX Discussions

I'm in the process of mocking / designing an application form that consists of many regions that will be broken out across 5 pages (I'm intentionally not using the APEX Wizard Component due to personal choice and given requirements). So I will need to store/persist all the pages' information temporarily, while user fills out the form and reviews and saves the application form on the last page. 

Based on a response to a previous question, it seems that apex_collections are the preferred way to do this versus using the values already in session state to persist the information during the session. I've spent a bit of time breaking the application form into logical groups of data that can be mapped to about 8 collections.

Questions:

  • Is this a correct assumption (using collections vs session state)?
  • Are there any performance considerations to think of when using APEX_COLLECTIONS?
  • How is it best to handle both the values in session state along with the the collections? Assuming you utilize the session state values to populate the page items on their associated page's regions, but use the collections for the last page when you save? So you are kind of maintaining the data twice, right? 
Tagged:

Best Answer

  • fac586
    fac586 Senior Technical Architect Member Posts: 20,114 Red Diamond
    edited Sep 23, 2021 2:20PM Accepted Answer

    Is this a correct assumption (using collections vs session state)?

    Strictly speaking, using collections as temporary data input storage is only really necessary when data in 1:M or M:M relationships is being captured using tabular forms, interactive grids, or repeated form pages. Session state should suffice for one dimensional data (and when 1:M/M:M relationships are represented by multi-select list/popup LOV/shuttle controls).

    Are there any performance considerations to think of when using APEX_COLLECTIONS (esp. if using 2 or 3 per page)?

    There will obviously be some extra overhead in saving and retrieving data from the collections in addition to setting session state, but this will be negligible for the volumes involved in manual data entry.

    How is it best to handle both the values in session state along with the the collections? Assuming you utilize the session state values to populate the page items on their associated page's regions, but use the collections for the last page when you save? So you are kind of maintaining the data twice, right? 

    There is an argument that pushing the data into collections on page submission and explicitly retrieving it on re-entering the page is safer as it can avoid glitches arising from any strange navigational anomalies the user manages to find.

    However the main benefits of using collections are that data can be stored using the correct data type and is easily exposed in SQL and DML for cross-page validation and final processing. Creating views over the collections is recommended as this provides an abstraction layer over the implementation, enabling processing to refer to data in a meaningful way, rather than opaque apex_collections, c001, n003 etc identifiers.

    McRiversStewStrykerNH

Answers

  • fac586
    fac586 Senior Technical Architect Member Posts: 20,114 Red Diamond
    edited Sep 23, 2021 2:20PM Accepted Answer

    Is this a correct assumption (using collections vs session state)?

    Strictly speaking, using collections as temporary data input storage is only really necessary when data in 1:M or M:M relationships is being captured using tabular forms, interactive grids, or repeated form pages. Session state should suffice for one dimensional data (and when 1:M/M:M relationships are represented by multi-select list/popup LOV/shuttle controls).

    Are there any performance considerations to think of when using APEX_COLLECTIONS (esp. if using 2 or 3 per page)?

    There will obviously be some extra overhead in saving and retrieving data from the collections in addition to setting session state, but this will be negligible for the volumes involved in manual data entry.

    How is it best to handle both the values in session state along with the the collections? Assuming you utilize the session state values to populate the page items on their associated page's regions, but use the collections for the last page when you save? So you are kind of maintaining the data twice, right? 

    There is an argument that pushing the data into collections on page submission and explicitly retrieving it on re-entering the page is safer as it can avoid glitches arising from any strange navigational anomalies the user manages to find.

    However the main benefits of using collections are that data can be stored using the correct data type and is easily exposed in SQL and DML for cross-page validation and final processing. Creating views over the collections is recommended as this provides an abstraction layer over the implementation, enabling processing to refer to data in a meaningful way, rather than opaque apex_collections, c001, n003 etc identifiers.

    McRiversStewStrykerNH
  • McRivers
    McRivers Member Posts: 66 Red Ribbon
    edited Sep 23, 2021 2:53PM

    Hey @fac586 ! Thanks for your response. So basically, it sounds like there is merit in both ways. There is no clear "right" way - so to speak.

    The point against using session state, as explained to me, is code maintainability. Encouraging me to not refer to page items "outside of their page scope" as this would be hard and confusing to maintain down the road for me or other developers.

    I will need to reference page item values from other pages throughout the multiple pages to build dynamic actions that would affect how forms were presented to the user. For example, on page 1 if P1_FORM_TYPE = 221 then on page 2, I would hide/show certain regions and page items based on the value of P1_FORM_TYPE.

    So I feel using session state would be easier to wire up, since it works out of the box, but see the reasoning in trying to keep page items limited to their page. I guess I'm trying to weigh if the extra programming (by using collections to limit page item scope) is worth the effort?

    There is an argument that pushing the data into collections on page submission and explicitly retrieving it on re-entering the page is safer as it can avoid glitches arising from any strange navigational anomalies the user manages to find.

    Are there any online examples/links you are aware of that show how to do this or is it pretty straightforward? (I've read the APEX_COLLECTIONS 21.1 API) Honestly, I just would like to do this the simplest way possible that will allow me to maintain easily in the future. I do not want to over-complicate things.

  • StewStrykerNH
    StewStrykerNH Member Posts: 84 Blue Ribbon

    Mike,


    IMHO, the cost/benefit analysis to your last question would include the number of pages and page items you're talking about. If the numbers of both are low (i.e. the product of the two variables is 15 or fewer), I'd just use page items. But more than that would justify the extra effort for all the collections overhead. I always figured if it was okay for the Data Upload Wizard to share page items across pages, it was good enough for me!

    It sounds like you're well past my arbitrary threshold.

    Finally, thanks for asking this great question so fac586 could provide their thoughtful answer! I hadn't heard these arguments for using collections, much less views of collections. I guess I've had my head in the sand (or elsewhere!) and missed recommended techniques like this.

    -- Stew