Many apps offer options for users to personalize the appearance and functionality of the app and developers commonly utilize tables to store these customizations.
One of the many features that APEX provides is the APEX_UTIL package, which includes a variety of useful functions and procedures to enhance application development. Among these functions, APEX_UTIL.SET_PREFERENCE stands out as a convenient tool for saving application preferences efficiently without the need to create tables or new columns.
To save a user preference, we have the choice to execute the following code either through PL/SQL, utilizing a page process known as User Preferences or a page computation.
In the example below, we will save the user's preferred choice for viewing a calendar.
BEGIN
APEX_UTIL.SET_PREFERENCE(
p_preference => 'CALENDAR_VIEW',
p_value => :P1_CALENDAR_VIEW,
p_user => :APP_USER);
END;
We also have the option to use a User Preference page process after submitting on the processing point to save that.
To retrieve the saved preference value and use it for customizing the app when users visit the calendar page, we can also utilize either PL/SQL, a page process or a computation.
BEGIN
:P1_CALENDAR_VIEW := APEX_UTIL.GET_PREFERENCE(
p_preference => 'CALENDAR_VIEW',
p_user => :APP_USER
);
END;
If we want to use a computation we can use as follows.
If we decide to eliminate the functionality or no longer want to save or maintain the user preference within the given context we can just delete the preference
BEGIN
APEX_UTIL.REMOVE_PREFERENCE(
p_preference => 'CALENDAR_VIEW',
p_user => :APP_USER);
END;
If you are still using tables as a means to store customizations specific to individual users, it is highly recommended that you begin utilizing the user preferences feature. This feature offers a more efficient and streamlined approach to managing user-specific settings and preferences.