Automatically Re-Enable APEX Automations After Deployment

Introduction
As you may know, when you deploy an APEX Application, APEX automatically disables all of the APEX Automations associated with that Application. This is perfectly fine in many scenarios, but when deploying to production, you nearly always want to restart all your Automations following the deployment. This post will describe two options for automating and re-enabling APEX Automations following a deployment.
Post Deployment SQL Script
This option involves creating a SQL script to loop through all Automations related to the APEX Application and re-activate them.
DECLARE
CURSOR cr_app_automations IS
SELECT app.application_id, app.workspace, atm.static_id
FROM apex_appl_automations atm
, apex_applications app
WHERE app.application_id = atm.application_id
AND app.alias = 'BACKGROUND-APEX';
BEGIN
-- Loop through all Automations for the Application.
FOR r_app_automation IN cr_app_automations LOOP
-- Set the Workspace / Security Group for the Application.
apex_util.set_security_group_id
(p_security_group_id => apex_util.find_security_group_id
(p_workspace => r_app_automation.workspace));
-- Enable the Automation.
apex_automation.enable
(p_application_id => r_app_automation.application_id,
p_static_id => r_app_automation.static_id);
END LOOP;
END;
The above script should be run after the APEX Application Deployment.
Supporting Objects Install Script
Another approach is to include the script as a Supporting Object Script, which will run automatically every time the Application is deployed.
Navigate to Application > Supporting Objects > Scripts > Install

Click the Create button:

Select ‘Create from Scratch’, and then click the Next Button:

Enter a name for the Script and click the Next button:

Copy and Paste the same script as option one above, and click the Create button.
APEX Builder Application Import
The next time you import the APEX Application, you will get the Option to Install Supporting Objects. Click this button to run the script to re-activate your APEX Automations.


After this step is complete, you can check the status of the install scripts by clicking the Install Summary button.

If you check the status of the Automations in the newly installed App, they should all be Active.

Command Line Import
If you import your app via the command line, you can call it apex_application_install.set_auto_install_sup_obj API to tell APEX to automatically run the supporting object scripts after the app has been imported.
BEGIN
apex_application_install.set_auto_install_sup_obj (p_auto_install_sup_obj => true);
END;
/
@f100.sql
Conclusion
This was a quick tip that will hopefully save time and prevent you from manually re-activating your APEX Automations after deploying an Application.






