Thursday, May 21, 2015

APEX - Error on sending email from DBMS_JOB in Apex

If we schedule a dbms_job that sends an email in Apex, we could encounter the following error:

ORA-20001: This procedure must be invoked from within an application session.

If you are using Apex_mail to send an email, the error will be of the form:

ORA-20001: This procedure must be invoked from within an application session. ORA-06512: at "APEX_050000.WWV_FLOW_MAIL", line 371 ORA-06512: at "APEX_050000.WWV_FLOW_MAIL", line 497 ORA-06512: at "APEX_050000.WWV_FLOW_MAIL", line 529 ORA-06512: at "APEX_050000.WWV_FLOW_MAIL_API"

This is because the context is not set and we are trying to send an email via APEX from DBMS_JOB.

We can set the context, we need to set the security group ID.

select workspace_id from apex_applications where application_id = :p_app_id;
  
You would know your application ID. 
 
apex_util.set_security_group_id(p_security_group_id => workspace_id);
  
You can put the above in a loop for multiple workspaces.
 
 

No comments:

Post a Comment