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.
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
- Create an account at onlinesmsservice.com
- Get your API key from the dashboard
- Register DLT templates for your SMS content
- Add Remote Site — Setup → Security → Remote Site Settings →
https://api.onlinesmsservice.com
Apex SMS Service Class
A reusable Apex class that handles authentication, error parsing, and callout logic.
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;
}
}
Trigger-Based SMS
Auto-send SMS when records are created or updated — perfect for order confirmations, case updates, and lead notifications.
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');
}
}
}
}
sendAsync method uses the @future(callout=true) annotation. For batch operations, consider using Queueable Apex instead.
Salesforce Flow Integration
No code required — use our invocable action in Flow Builder to send SMS from any automated flow.
Steps to Set Up
- Deploy the
SMSServiceApex class to your org - Open Flow Builder
- Add an Action element
- Search for "Send SMS" — our invocable action
- Map the Phone Number and Message fields
- 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
Using Named Credentials (Recommended)
Store your API key securely in Salesforce Named Credentials instead of hardcoding it in Apex.
Setup Steps
- Go to Setup → Named Credentials
- Create new credential named
OnlineSMSService - URL:
https://api.onlinesmsservice.com - Auth Protocol: Custom Header
- 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
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
@futurefor single sends from triggers - Use
QueueableApex 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.