How to send SMS from Oracle APEX

In today’s digitalized business solution world, SMS notifications are one of the fastest ways to reach users. Whether it’s for OTP (One-Time Password), reminders, or alerts, integrating SMS with your Oracle APEX application can add huge value. In this guide, we’ll walk through different ways to send SMS from Oracle APEX. For better understand follow this Tutorial in Youtube.


Why Send SMS from Oracle APEX?

Oracle APEX already provides built-in features for sending emails, but sometimes email isn’t enough. SMS can be useful for:

  • OTP & Two-factor Authentication

  • Order Confirmations Text

  • Notifications

  • Promotional Messages


Process to Send SMS in Oracle APEX

1. Register with Third Party SMS Gateway

Most SMS providers (like Twilio, Nexmo, or local telecom gateways) expose a REST API to send SMS. Oracle APEX supports REST integrations, so you can call these APIs directly.

Steps:

  1. Choose an SMS provider (e.g., Twilio, Nexmo, Clickatell, or your local telecom).

  2. Get your API credentials (API Key, SID, Auth Token, etc.).




2. Create Application Page To Send SMS

In this step you need to create a page to send SMS from your application. In my case, I have try to shown in two ways to send SMS. First, try to send SMS to a single receiver. And lastly shown how to send SMS to multiple users at a time.




3. Create AJAX Callback Process to Prepare Mobile No. Lists of Receivers

 Select process tab on the left side navigation pane and follow the below process-
1. select AJAX Callback.
2. Right Click here and select Create Process.
3. Paste the below code Source > PL/SQL Code in properties section-

        BEGIN

                apex_json.open_array;

                FOR I IN (

                        SELECT last_name

                                , phone_number

                                , ‘Dear ‘||last_name||’, ‘||chr(10)||’Your salary is BDT‘||salary||’ transferred to your bank.’||chr(10)||’Thank You’||chr(10)||’Payroll Section’ AS MSG

                        FROM employees

                        WHERE INSTR(‘:’||REPLACE(apex_application.g_x01,’,’,’:’)||’:’,’:’||employee_id||’:’) > 0

                ) LOOP

                        apex_json.open_object;

                        apex_json.write(‘NAME’, i.last_name);

                        apex_json.write(‘MOBILE’, i.phone_number);

                        apex_json.write(‘MSG’, i.msg);

                        apex_json.close_object;

                END LOOP;

                apex_json.close_all;

        END;

Note: Please replace appropriate single code in your pl/sql code editor.




4. Create Javascript Function to Execute AJAX Callback Process

Select page from the left side navigation pane. Select Javascript > Function and Grobal Variable Declaration. Open the code editor and paste the below code-
        function sendSms(msg, to) {
            var url = “Your API URL here"; // Must return json data
            data = new FormData()
            data.set('token', ‘Your TOKEN here')
            data.set('message', msg)
            data.set('to', to)

            var xhr = new XMLHttpRequest();
            xhr.open("POST", url, true);

            xhr.send(data);
            xhr.onload = function() {
                var response = JSON.parse(this.responseText);
                console.log(response);
                apex.message.showPageSuccess(response[0].statusmsg);
            };
        }        



5. Create Dynamic Action to SEND_SMS button
Set the below properties for that dynamic action-

        a. Name-    Send Bulk SMS
        b. Change the true action
                Action- Execute Javascript Code
                Code - 
                            
var arr = [] ;
                            arr.push($v('P38_SELECTED_EMP'));

                            if (arr[0] != '') {
                                apex.server.process(
                                    'PREPARE_DATA'
                                    , {
                                        x01: $v('P38_SELECTED_EMP')
                                    }
                                   , {
                                        dataType: 'json' ,
                                        success: function(pData) {
                                            for (var i = 0; i < pData.length; i++) {
                                            sendSms(pData[i].MSG, pData[i].MOBILE);
                                    }
                                }
                            }
                        )
                    } else {
                        apex.message.showErrors(
                            [
                                {
                                    type: 'error' ,
                                    message: 'No employee selected to send SMS!' ,
                                    location: 'page',
                                    unsafe: false
                                }
                            ]
                        )
                    }

Conclusion

Sending SMS from Oracle APEX is straightforward if you use an SMS Gateway API like Twilio, Nexmo, or your local provider. By leveraging AJAX callback process and javascript function, you can easily send OTPs, alerts, and notifications from your APEX applications.

Start small with a test SMS, then integrate it into your workflows—your users will appreciate the instant updates! 


Comments

Post a Comment