A simple tool to invalidate all the email addresses in your Salesforce org. This is meant to be used in Sandboxes to avoid accidentally sending email to everyone in the org (which comes up more than people expect).
Currently this tool consists of unpackaged metadata. At some point I'll work on getting it packaged, but this is still an early draft.
This project is loose metadata, not a package, so you install it by deploying the source with the Salesforce CLI.
- Salesforce CLI (
sf). - A user in the target org who can deploy metadata, such as a System Administrator.
- A sandbox if you only want to invalidate emails in that sandbox.
- Production if you want the app to stay around after refreshes. The project provides a Sandbox Post Copy Process to run when you create or refresh sandboxes. Nothing runs in this project unless someone starts it.
-
Clone the repository:
git clone https://github.com/acrosman/SalesforceInvalidateEmail.git cd SalesforceInvalidateEmail -
Log in to the org and give it an alias. For a sandbox add
--instance-url https://test.salesforce.com:sf org login web --alias invalidator-target
-
Deploy the source. Production deploys must run the Apex tests, so add
--test-level RunLocalTeststhere:sf project deploy start --source-dir force-app --target-org invalidator-target
-
Assign the Invalidate Emails permission set to each user who will run the tool (see Permission Sets):
sf org assign permset --name Invalidate_Emails --target-org invalidator-target
Without --on-behalf-of this assigns it to the logged-in user. You can also assign it in Setup under Permission Sets.
The deploy includes a field record for Contact.Email and the Invalidation_Text setting set to .invalid. Deploying again later resets those two records to the values in this repository.
- Open the app launcher and search for
Invalidate Emailto open the Invalidate Email Addresses app. - Choose the email fields to invalidate.
Contact.Emailis included. To add more fields, either:- Click Scan For Email Fields. When the scan job finishes, the Email Field Scanner Results card lists email fields that aren't configured yet. Select the ones you want and click Include Selected Fields.
- Or click Manage on the Invalidate Email Fields Configuration card, click New, and pick the Object and Field Name.
- Optionally, change the text added to each address in the Email Invalidator Settings card and click Save & Deploy. The default is
.invalid.
Scanned fields and settings are saved by deploying Custom Metadata, which finishes in the background. They can take a minute to appear. When you include scanned fields, you get an email once their deploy finishes.
- Check Setup > Email > Deliverability. Until emails are invalidated it is safest to set access to System email only or No access. New sandboxes start at System email only.
- Click Invalidate Emails. One batch job starts for each configured object.
- Follow the jobs in the Email Invalidator Jobs card. When they finish, the Field Invalidation Status card shows how many values in each field are invalidated.
To undo it, click Restore Emails, which removes the invalidation text from the configured fields.
You can find the app in the app switcher by searching for Invalidate Email.
The project provides an Invalid Email App which shows a list of the fields that are setup to be invalided, and a Lightening Web Component to initiate the process of adding .invalid (or other user provided text) to the end of all values in that field.
You can add Custom Metadata records to list all email fields on any object, so all emails can be disabled.
Email fields are limited to 80 characters, so the invalidated value is kept within the field's limit:
- If the invalidated value fits, the invalidation text is appended as usual.
- If the invalidated value is greater than 80 characters, the value is cut off at the limit (for example ending in
.inv). These addresses can still be fully restored. - If the address is 80 characters, the end of the address is removed to make room for the full invalidation text. These addresses can NOT be fully restored.
The Email Invalidator Jobs card on the app page lists the invalidate, restore, and field scan batch jobs from the last 7 days, with their status, progress, and any errors. While jobs are queued or running the card refreshes itself every few seconds, and it stops once they have all finished. The object each job is processing is shown for jobs started from the page during your current visit.
The Field Invalidation Status card lists each configured email field with the number of records that have a value in that field and the percentage of those values that currently end with the invalidation text. Each field is counted separately, so if one field can't be counted its row shows the error and the others still load. The card refreshes itself when an Email Invalidator job finishes.
Anyone you want to be able to use this process should be assigned the included Invalidate Emails permission set.
Users who only need to build or run flows that use the Invalidate All Configured Emails or Restore All Configured Emails flow actions can instead be assigned the Invalidation Flow Users permission set.
There is also a SandboxPostCopy class you can use to have the process run as soon as a Sandbox refresh or create completes. This is only useful in a full or partial copy sandbox.
When you create a sandbox there is a field that allows you to indicate classes you want run after the process completes. Enter InvalidateEmailSandboxPostCopy and the process defined here will run.
The class and the field records must be deployed to production for this to work, because the new sandbox gets its metadata from production. It invalidates the fields configured in production when the sandbox was copied.
Feedback is welcome, and even appreciated. Please create a new Issue and submit your ideas.
