To send an SMS from Salesforce Apex, make an HTTP callout to POST /v1/messages from a Queueable class that implements Database.AllowsCallouts, with the API key held in a Named Credential rather than in code. Store one Idempotency-Key UUID on the record so a retried job never texts the same person twice.
Apex adds a few wrinkles that other languages don't: you can't call out from inside a trigger's own transaction, secrets belong in credentials and not in custom settings, and governor limits shape how you batch. This post covers each, with code you can adapt.
The shape of the call
The request is the same as anywhere else. The base URL is https://api.tryready.com, the key travels in an X-API-Key header, and the JSON body has to (E.164), body and consent_attested. Leave from out and Ready picks the number: the one this contact already texts with, otherwise your number closest to their area code.
{"to": "+12125550199", "body": "Your appointment is tomorrow at 10:00.", "consent_attested": true} Set consent_attested to true only when the person agreed to texts, and keep that consent in a field on the record. Ready records the sender's attestation per API send, but it doesn't store a per-contact opt-in; your org is the system of record for that.
Put the key in a Named Credential
Create an External Credential and a Named Credential that points at https://api.tryready.com. Add the API key as a credential parameter and have the credential send it as a custom X-API-Key header, then grant the permission set that runs your code access to it. Your Apex never sees the key, it can't leak into debug logs or a repo, and rotating it is a credential edit instead of a deploy.
The Apex endpoint is then callout:Ready_API/v1/messages, where Ready_API is whatever you named the credential. Remote Site Settings aren't needed for a Named Credential. See API key security and rotation for rotating without a gap.
A Queueable that sends one text
A trigger can't make a callout before its transaction commits, so the trigger enqueues a job and the job makes the call. This sketch texts a lead when it's created; the custom fields (Ready_Text_Key__c, Ready_Text_Status__c) are examples you'd add yourself.
public class ReadySmsJob implements Queueable, Database.AllowsCallouts {
private Id leadId;
public ReadySmsJob(Id leadId) { this.leadId = leadId; }
public void execute(QueueableContext ctx) {
Lead l = [SELECT Id, MobilePhone, Ready_Text_Key__c, Ready_Text_Status__c
FROM Lead WHERE Id = :leadId];
if (l.Ready_Text_Status__c == 'sent' || String.isBlank(l.MobilePhone)) return;
HttpRequest req = new HttpRequest();
req.setEndpoint('callout:Ready_API/v1/messages');
req.setMethod('POST');
req.setTimeout(20000);
req.setHeader('Content-Type', 'application/json');
req.setHeader('Idempotency-Key', l.Ready_Text_Key__c);
req.setBody(JSON.serialize(new Map<String, Object>{
'to' => l.MobilePhone,
'body' => 'Thanks for your interest. Want to book a call this week?',
'consent_attested' => true
}));
HttpResponse res = new Http().send(req);
if (res.getStatusCode() == 429 || res.getStatusCode() >= 500) {
l.Ready_Text_Status__c = 'retry';
} else if (res.getStatusCode() >= 200 && res.getStatusCode() < 300) {
l.Ready_Text_Status__c = 'sent';
} else {
l.Ready_Text_Status__c = 'refused';
System.debug('Ready refused: ' + res.getStatusCode() + ' ' + res.getBody());
}
update l;
}
} The key is set in a before-insert trigger with UUID.randomUUID().toString(), so it exists before the job ever runs and stays the same however many times the job reruns. Then an after-insert trigger calls System.enqueueJob(new ReadySmsJob(lead.Id)). DML after a callout is fine; the reverse order is the one Salesforce blocks.
Retries without duplicates
A record in retry status is picked up by a scheduled job that enqueues it again with the same key. If the first attempt reached Ready but the response was lost, the second attempt doesn't send another text. That's the point of the header.
Retry only what a retry can fix: a timeout, a 429 or a 5xx. A 4xx means Ready refused the request, such as a bad number or an opted-out contact, and sending it again won't help. Mark it refused, keep the response body for whoever owns the data, and see the error reference for the codes. SMS API retries and failure handling goes further.
If a timeout leaves you unsure whether a text went out, look at GET /v1/messages before creating a new key. A new key means a new message.
Check opt-outs before you text from Salesforce
Salesforce has its own Do Not Contact and email opt-out fields, and they know nothing about a STOP reply that arrived through Ready. Ready blocks sends to numbers that opted out in the sub-account that received the STOP, and refuses them up front without charge. But when texts come from more than one tool, or you're migrating, check first.
Call GET /v1/opt-outs/:phone before the first send, and again from a scheduled job that syncs recent opt-outs into a checkbox on the Lead or Contact. GET /v1/opt-outs lists opted-out contacts on the account, and GET /v1/opt-outs?scope=all adds the whole Ban list. The opt-outs docs describe both, and our post on syncing opt-outs across channels covers the design.
A STOP always blocks that number in the sub-account that received it. Whether it also blocks the parent and the other sub-accounts is decided by Ready, so use the per-number check when it matters.
Governor limits, in general terms
Salesforce limits how many callouts one transaction can make, how long each can take, and how many Queueable jobs you can chain or enqueue. The exact numbers change by release and edition, so check the current Apex limits page rather than trusting a figure from a blog post, including this one. The design consequences are stable:
- One text per job is the simplest and the easiest to retry, but it uses a lot of jobs on a big import.
- For a few dozen recipients,
POST /v1/messages/bulktakes up to 100 recipients per call, which cuts callouts sharply. Split bigger lists into batches. - A Batch Apex class that calls
Database.AllowsCalloutswith a small scope size keeps each transaction well inside the limits. - Never loop callouts inside a trigger handler. Enqueue and return.
With the bulk route, keep one Idempotency-Key per batch and store it on the batch record, not on each lead.
Cost and registration
A segment costs $0.0075 plus a $0.0045 carrier fee. A card on file and a number of your own ($2 a month) are required. An account can send up to 500 texts a month before it registers for 10DLC, and most approvals take 2 to 7 days. Accounts opened before November 12, 2026 keep their signup prices, shown under Billing. See the pricing page. If you'd rather connect than code, our overview of CRM texting integrations lists the options.
Frequently asked questions
Can I call the API directly from a trigger?
Not synchronously. Enqueue a Queueable (or use a platform event) from the trigger and make the callout there.
Do I need a Remote Site Setting?
Not when you use a Named Credential. The credential carries the endpoint and authentication.
Does Ready read Salesforce's Do Not Contact field?
No. Ready keeps its own opt-outs, so sync them into Salesforce yourself with the opt-out endpoints, and check your own field before you enqueue a text.
The short version
Hold the key in a Named Credential, call out from a Queueable, store one idempotency UUID on the record, check opt-outs before the first send, and design around the platform's limits without hard-coding them. The API quickstart shows the first send end to end. When you're ready to test, sign up and send from your own number.