CRM Integration

Salesforce SMS Gateway Integration

Apex callouts, trigger-based SMS, Flow actions, and managed-package install — connect your CRM to SMS in minutes.

☁️

Managed Package

Install our AppExchange package for zero-code SMS from Salesforce — no Apex required.

Trigger-Based

Auto-send SMS on record creation, updates, or field changes with Apex triggers.

🔗

Flow Compatible

Use our invocable Apex actions in Salesforce Flows for admin-friendly SMS automation.

Before You Begin

Prerequisites

Salesforce Requirements

  • Salesforce Enterprise, Unlimited, or Developer Edition
  • API access enabled in your org
  • Remote Site Settings configured for our API endpoint
  • Named Credential (recommended for security)

OnlineSMSService Setup

  1. Create an account at onlinesmsservice.com
  2. Get your API key from the dashboard
  3. Register DLT templates for your SMS content
  4. Add Remote Site — Setup → Security → Remote Site Settings → https://api.onlinesmsservice.com
Method 1

Apex SMS Service Class

A reusable Apex class that handles authentication, error parsing, and callout logic.

Apex — SMSService.cls
public class SMSService {
    private static final String ENDPOINT = 'https://api.onlinesmsservice.com/v1/sms/send';
    private static final String API_KEY  = 'YOUR_API_KEY';  // Use Named Credential instead

    // Synchronous send (for triggers, use @future)
    @future(callout=true)
    public static void sendAsync(String phone, String message, String msgType) {
        Http http = new Http();
        HttpRequest req = new HttpRequest();
        req.setEndpoint(ENDPOINT);
        req.setMethod('POST');
        req.setHeader('Content-Type', 'application/json');
        req.setHeader('Authorization', 'Bearer ' + API_KEY);
        req.setTimeout(30000);

        Map<String, Object> payload = new Map<String, Object>{
            'to'      => phone,
            'message' => message,
            'sender'  => 'YOURID',
            'type'    => msgType
        };
        req.setBody(JSON.serialize(payload));

        try {
            HttpResponse res = http.send(req);
            if (res.getStatusCode() == 200) {
                Map<String, Object> body = (Map<String, Object>) JSON.deserializeUntyped(res.getBody());
                System.debug('SMS sent — ID: ' + body.get('message_id'));
            } else {
                System.debug('SMS failed — ' + res.getStatusCode() + ': ' + res.getBody());
            }
        } catch (Exception e) {
            System.debug('SMS error: ' + e.getMessage());
        }
    }

    // Invocable method for Flows
    @InvocableMethod(label='Send SMS' description='Send SMS via OnlineSMSService')
    public static void sendFromFlow(List<SMSRequest> requests) {
        for (SMSRequest r : requests) {
            sendAsync(r.phone, r.message, r.messageType ?? 'transactional');
        }
    }

    public class SMSRequest {
        @InvocableVariable(required=true label='Phone Number')
        public String phone;

        @InvocableVariable(required=true label='Message')
        public String message;

        @InvocableVariable(label='Message Type (transactional/promotional)')
        public String messageType;
    }
}
Method 2

Trigger-Based SMS

Auto-send SMS when records are created or updated — perfect for order confirmations, case updates, and lead notifications.

Apex — CaseSMSTrigger.trigger
trigger CaseSMSTrigger on Case (after update) {
    for (Case c : Trigger.new) {
        Case old = Trigger.oldMap.get(c.Id);

        // Send SMS when case status changes to "Resolved"
        if (c.Status == 'Resolved' && old.Status != 'Resolved') {
            Contact contact = [
                SELECT Phone FROM Contact WHERE Id = :c.ContactId LIMIT 1
            ];

            if (contact != null && contact.Phone != null) {
                String msg = 'Your support case #' + c.CaseNumber
                    + ' has been resolved. Thank you for your patience.';
                SMSService.sendAsync(contact.Phone, msg, 'transactional');
            }
        }
    }
}
⚠️ Important: Apex triggers cannot make synchronous callouts. That is why the sendAsync method uses the @future(callout=true) annotation. For batch operations, consider using Queueable Apex instead.
Method 3

Salesforce Flow Integration

No code required — use our invocable action in Flow Builder to send SMS from any automated flow.

Steps to Set Up

  1. Deploy the SMSService Apex class to your org
  2. Open Flow Builder
  3. Add an Action element
  4. Search for "Send SMS" — our invocable action
  5. Map the Phone Number and Message fields
  6. Activate the Flow

Common Flow Use Cases

  • New lead welcome SMS
  • Opportunity stage change notifications
  • Appointment reminders (scheduled flows)
  • Order status updates from custom objects
  • Survey follow-ups after case closure
Security

Using Named Credentials (Recommended)

Store your API key securely in Salesforce Named Credentials instead of hardcoding it in Apex.

Setup Steps

  1. Go to Setup → Named Credentials
  2. Create new credential named OnlineSMSService
  3. URL: https://api.onlinesmsservice.com
  4. Auth Protocol: Custom Header
  5. Header: Authorization, Value: Bearer YOUR_KEY

Updated Apex Code

// Replace hardcoded endpoint with Named Credential
req.setEndpoint('callout:OnlineSMSService/v1/sms/send');
// Remove the Authorization header — it is auto-added
Best Practices

Production Checklist

🔐 Security

  • Use Named Credentials — never hardcode API keys
  • Create a dedicated Integration User profile
  • Enable field-level security on phone fields
  • Log all SMS sends in a custom object for audit

⚡ Governor Limits

  • Use @future for single sends from triggers
  • Use Queueable Apex for batch SMS
  • Stay within 100 callouts per transaction
  • Test with Test.setMock() — no live calls in tests

Connect Salesforce to SMS Today

Get 500 free SMS credits upon successful registration and DLT mapping with an approved telemarketer. Deploy our Apex class and start sending from your CRM.