Integrations
Validate phone numbers and emails in Salesforce
Verify lead and contact emails and phone numbers from Salesforce with an Apex callout, a Named Credential and a Queueable job that writes the result to fields.
Updated 2026-11-23
This recipe checks the email and phone number of each new Lead with an Apex Queueable job, stores the result in custom fields and lets you route on it with a flow or a report. Salesforce has no native Qelka integration, so the call goes through a Named Credential.
What you need
- A Salesforce org where you can create Apex classes, triggers, a Named Credential and custom fields. Apex needs a sandbox, or a production org with the right edition: check yours.
- A Qelka API key stored in a Salesforce External Credential. A
sk_test_key returns simulated results and never spends credits: see Test mode. - Custom fields on Lead (and Contact if you want it):
Email_Status__c(text),Email_Suggestion__c(text),Phone_E164__c(text) andValidation_Checked__c(checkbox). The code readsCountryCode, which exists when state and country picklists are enabled: otherwise map your own country field.
Steps
1. Create the credential
In Setup, create an External Credential with a Custom authentication protocol, add a principal, and add an authentication parameter named Authorization with the value Bearer sk_live_your_key (or a sk_test_ key while you build). Name the External Credential Validate_Credential. Then create a Named Credential named Validate_API with the URL https://api.qelka.com/v1, link it to that External Credential, and add a custom header named Authorization with the value {!$Credential.Validate_Credential.Authorization}. Grant the running users access through a permission set.
The exact screens change between Salesforce releases, so follow the current Salesforce documentation for External Credentials. The goal is that the key is stored by the platform and Apex only names the credential.
2. The Apex class
public with sharing class SignupValidator implements Queueable, Database.AllowsCallouts {
private final List<Id> leadIds;
public SignupValidator(List<Id> leadIds) {
this.leadIds = leadIds;
}
public void execute(QueueableContext context) {
List<Lead> leads = [SELECT Id, Email, Phone, CountryCode FROM Lead WHERE Id IN :leadIds];
List<Lead> changes = new List<Lead>();
for (Lead lead : leads) {
Lead changed = new Lead(Id = lead.Id, Validation_Checked__c = false);
if (String.isNotBlank(lead.Email)) {
Map<String, Object> result = post('/email', new Map<String, Object>{ 'email' => lead.Email, 'mode' => 'fast' });
if (result != null) {
changed.Email_Status__c = (String) result.get('status');
changed.Email_Suggestion__c = (String) result.get('did_you_mean');
changed.Validation_Checked__c = true;
}
}
if (String.isNotBlank(lead.Phone)) {
Map<String, Object> body = new Map<String, Object>{ 'phone' => lead.Phone };
if (String.isNotBlank(lead.CountryCode)) {
body.put('country', lead.CountryCode);
}
Map<String, Object> result = post('/phone', body);
if (result != null && result.get('status') == 'valid') {
changed.Phone_E164__c = (String) result.get('e164');
}
}
changes.add(changed);
}
update changes;
}
private static Map<String, Object> post(String path, Map<String, Object> body) {
for (Integer attempt = 1; attempt <= 2; attempt++) {
HttpRequest request = new HttpRequest();
request.setEndpoint('callout:Validate_API' + path);
request.setMethod('POST');
request.setHeader('Content-Type', 'application/json');
request.setBody(JSON.serialize(body));
request.setTimeout(20000);
try {
HttpResponse response = new Http().send(request);
if (response.getStatusCode() >= 200 && response.getStatusCode() < 300) {
return (Map<String, Object>) JSON.deserializeUntyped(response.getBody());
}
if (response.getStatusCode() != 429 && response.getStatusCode() < 500) {
System.debug(LoggingLevel.WARN, 'validation skipped: status ' + response.getStatusCode() + ' request ' + response.getHeader('X-Request-Id'));
return null;
}
} catch (CalloutException error) {
System.debug(LoggingLevel.WARN, 'validation skipped: ' + error.getMessage());
return null;
}
}
return null;
}
}
The callout is limited by Apex governor limits, such as the number of callouts and the total time in one execution: keep the chunk small and check the current limits for your edition. A failed call leaves Validation_Checked__c false and never blocks the save. mode: 'fast' skips the mailbox check so the job stays short: see the email reference.
3. The trigger
trigger LeadValidation on Lead (after insert) {
List<Id> ids = new List<Id>();
for (Lead lead : Trigger.new) {
ids.add(lead.Id);
}
if (!ids.isEmpty() && !System.isBatch() && !System.isFuture()) {
System.enqueueJob(new SignupValidator(ids));
}
}
A trigger can enqueue one job per transaction with a bounded chunk. If you import thousands of leads at once, load them in batches of a few dozen, or use Batch Apex.
4. Route on the status
Build a record-triggered flow on the Email_Status__c field:
| Value | Meaning | Suggested action |
|---|---|---|
undeliverable |
Bad syntax, no domain or no mailbox | Mark the lead as bad email, notify the owner with Email_Suggestion__c when it is not empty |
risky |
Disposable inbox, catch-all domain or full mailbox | Add to a review queue |
deliverable |
The mail server accepted the mailbox | Continue the normal flow |
unknown or empty |
Not conclusive, or the check did not run | Continue, and re-check later |
An unknown email is not a bad email, so do not delete the lead. See the email reference for each reason, and Block disposable email signups for the disposable case. Store Phone_E164__c and use it for calling and messaging: Format phone numbers in E.164 explains why.
Handle errors and rate limits
No error is billed. 401 invalid_api_key and 403 forbidden mean a wrong or restricted key. 402 insufficient_credits means an empty balance: alert yourself and keep failing open. A key allows 200 requests per 10 seconds, then you get 429 rate_limited, and Retry-After says how long to wait. Each email check costs 1 credit. See Errors and Rate limits.
Related
Frequently asked questions
Why a Queueable job and not a call in the trigger?
Where does the API key go in Salesforce?
Can I check existing records?
Put this check in your product
Get an API key in under a minute. 100 free credits every month, no card required.
- 100 free credits a month
- No card
- Test keys spend nothing
- Cancel any time