Integrations · CRM
Validate emails in Salesforce
Our Salesforce package checks the email addresses of your Leads and Contacts and stores the result on each record: when a record is saved, for a whole list at once, or from your own flows. It uses your API key through a Salesforce Named Credential, so the key never sits in a field, in code or in a log.
The package is not on AppExchange yet. It is a Salesforce DX project that you download and deploy to your org with the Salesforce CLI. It is Apex code, so it needs an edition that can deploy Apex, such as Enterprise, Unlimited or Developer Edition: Professional and Group editions do not support Apex outside managed AppExchange packages, so the deploy cannot run there.
What it adds to your org
- Three fields on Lead and Contact: Email Validation Status (one of the five result statuses:
valid,invalid,catch_all,unknownordisposable), Email Validation Reason and Email Validated At. You can send the results to fields of your own instead. - Validate on save: a check when a record is created with an email address or its address changes.
- List clean: a check of every Lead or Contact that a filter picks, for example all records without a status.
- Two flow actions in the category Email Validation: Validate Email (one record or address) and Clean Email List.
- A permission set, Email Validation, and the settings below. Both automatic checks are off until you switch them on, so deploying the package spends no credits.
Get the package
Download email-validation-salesforce.zip and unzip it. The folder email-validation-salesforce is the Salesforce DX project: Apex classes with their tests, two triggers, the fields, a custom setting, a custom metadata type, a run object, the credentials and the permission set, with a manifest/package.xml that lists them all. Nothing in it holds a key.
Deploy it
Try it in a sandbox or a Developer Edition org first. With the Salesforce CLI installed and signed in to your org, run this in the project's folder:
sf project deploy start --manifest manifest/package.xml --target-org <your-org-alias> \
--test-level RunSpecifiedTests \
--tests EmailValidationClientTest --tests EmailValidationActionTest \
--tests EmailValidationOnSaveTest --tests EmailValidationBulkTestThe deploy runs the package's Apex tests in your org. They answer every API call with a stand-in, so they make no real call and cost nothing. They create test Leads and Contacts: if your org's required fields, validation rules or blocking duplicate rules refuse those, the deploy stops and says which rule did, which is one more reason to start in a sandbox.
Add your API key
- On the API keys page, create a key for Salesforce with the permission Validate addresses, and Bulk lists too if you will clean lists. Leave its allowed origins empty: Salesforce sends no
Originheader. A daily credit cap limits what a busy org can spend. - In Salesforce Setup, open Named Credentials → External Credentials → Email Validation. Under Principals, edit EmailValidationKey, add an Authentication Parameter named
ApiKeyand paste your key. Save. - Open Setup → Permission Sets → Email Validation → Manage Assignments and add every user whose saves should trigger a check (everyone who creates or edits Leads and Contacts, integration and data-load users included), whoever cleans lists, and the user who schedules cleans. A check runs as the user who saved the record, and without the permission set its call to our API is refused by Salesforce.
The key travels only to our API's address (https://api.email-validation.org, or https://api-eu.email-validation.org for the EU), which the package's two Named Credentials fix, and only in a request header.
Validate on create and update
Open Setup → Custom Settings → Email Validation Settings → Manage and create the default for your organization with Validate On Save ticked. A record for one profile or user overrides it, for example to switch it off for a data-load user.
From then on:
- A Lead or Contact that is created with an email address, and has no status yet, is checked.
- A record whose email address changes is checked again. A change only in upper or lower case is not a change, and edits to other fields check nothing.
- The check runs right after the save, in the background (Salesforce does not allow a call to another service during the save itself), and writes the result to the record. That write never starts another check.
- One save of many records, such as an import, queues at most 10 background jobs. Records beyond that, and records whose check failed because the account had no credits or the key was refused, keep an empty status: a list clean with the filter
Email_Validation_Status__c = nullchecks them later. - When the API asks to slow down or is briefly unavailable, the job tries those records again after the wait the API asks for, up to 3 times in all.
- When a Lead is converted, its new Contact is checked again unless the three fields go with it: map them in Setup → Object Manager → Lead → Fields & Relationships → Map Lead Fields.
If you set Region to eu in the same settings, every check is made in the EU and its result is stored there.
Clean a list
Tick Bulk Clean Enabled in Email Validation Settings. Then start a clean with the flow action Clean Email List (for example from a screen flow behind a button) or from the Developer Console (Debug → Open Execute Anonymous Window):
EmailValidationBulkClean.start('Lead', 'Email_Validation_Status__c = null', null);The first value is Lead or Contact. The second is a SOQL condition that picks the records, read with your own access to them: the filter of a list view or report written as SOQL, a campaign (Id IN (SELECT LeadId FROM CampaignMember WHERE CampaignId = '701…')), or empty for every record with an email address. The third is the region (global or eu; empty: the one in the settings).
Each clean is an Email Validation Run record that shows where it stands and how many records it updated. To see them, create a tab for Email Validation Runs (Setup → Tabs → New) and add it to an app, or report on them. Everyone with the permission set sees every run; only the user who started a run (and users above them in the role hierarchy), or an admin, can stop or resume it.
Up to 50 records are checked one by one.
More records become one bulk job per 20,000 records. The run uploads the addresses with their record ids, saves the job's id, and only then starts the job, which is when its credits are held. It follows the job until it has finished, reads its results, and writes each record's status and reason back. A record whose address changed since the upload is left as it is (with validate on save on, the new address has its own check).
When something stops a run, such as a refused key, too few credits or the key's daily cap, its Stage is Stopped and Error Code says why. Fix the cause, then resume it:
EmailValidationBulkClean.resume('<run id>');A resumed run continues the same bulk job, so the list is never paid for twice (within the 30 days a list is kept).
EmailValidationBulkClean.stopstops a run after its current step. A run that is still going is not resumed (conflict): stop it first, or resume it once it has not moved for 30 minutes.A job that stays ready but will not start, for example an upload too old to start, stops the run after 5 tries, with Error Message saying why.
The same list cannot be started again while a clean of it is still going.
To clean new records every night, and to pick up runs that stopped moving for 30 minutes, schedule the package's scheduler once, as an admin (a scheduler picks up only the runs its user may change: every run for an admin, otherwise its user's own):
System.schedule('Email Validation: new Leads', '0 0 3 * * ?',
new EmailValidationBulkScheduler('Lead', 'Email_Validation_Status__c = null'));A scheduler without a list only picks up runs that stopped moving. Every hour is a good pace for it:
System.schedule('Email Validation: revive', '0 0 * * * ?', new EmailValidationBulkScheduler());Developer Edition and trial orgs stop a chain of background jobs after five steps unless its first job allows more. A clean's first step allows more, so long lists run there too; a run that stops moving anyway is picked up by the revive schedule above.
Before you deploy a new version of the package, stop the cleans that are running and resume them after the deploy. A step queued by the old version does nothing in the new one, and Salesforce may refuse to deploy a class while its jobs are queued.
Send the results to your own fields
Open Setup → Custom Metadata Types → Email Validation Field Map → Manage Records and edit the record Lead or Contact:
| Field | What it takes | When empty |
|---|---|---|
| Status Field | the API name of a picklist or text field | the package's Email Validation Status |
| Reason Field | a text or picklist field | the reason is not written |
| Validated At Field | a date/time or date field | the time is not written |
A picklist that receives the status needs the five status values. If a field does not exist or has another type, no check is made and the error code is invalid_field_map, so nothing is charged for a result that cannot be stored.
Use it in your own flows
The Validate Email action checks one Lead or Contact (input Record ID) or one address (input Email, returned but not saved). Use it on a record-triggered flow's Run Asynchronously path, instead of Validate On Save, not as well. Its outputs include Status, Reason, Action (send, send_with_caution, remove or retry_later), Did you mean, Saved, Error code and Retry after (seconds), so a Decision can act on the result.
The error codes are the API's own and these from Salesforce's side:
| Error code | What it means |
|---|---|
| no_email | The record has no email address. Nothing was checked. |
| record_not_found | The record was deleted, or the user cannot see it. |
| callout_limit | Salesforce's limit on calls in one transaction was reached. The rest was not checked: run it again, or clean the list. |
| save_failed | The result came back but the record could not be saved, for example a converted Lead. |
| invalid_field_map | A field in the field map does not fit. |
| connection_error | No answer arrived. The message carries Salesforce's reason, such as a missing permission. |
Try it for free first
Give a test Lead the address accepted@sandbox.email-validation.org, no_mailbox@sandbox.email-validation.org or disposable@sandbox.email-validation.org: each test address returns the status its name says and costs nothing.
Costs
- Each check of an address costs one credit, as anywhere else. Results with the status
unknownand the test addresses are free. - A list clean's bulk job holds credits for its unique addresses when it starts and returns what it does not use. Duplicates in the list are checked once.
- The daily credit cap of the key you gave Salesforce applies to everything the package does.