JULY 30, 2021 UPDATE: This version is now outdated! Please go here for the latest.
Unsubscribe Link 2.2 (OUTDATED)
Allow Recipients to Unsubscribe From All Email Sent via Salesforce
When the recipient clicks to unsubscribe, a flow will look for all contacts and leads who have this email in the Email field and mark them “Email Opt Out.” The email address owner will receive one confirmation email immediately. A custom object tracks when someone unsubscribes to allow you to report on it.
See How It Works
UPDATE: 1/28/21 I realized how to send the confirmation email from someone other than “Site Guest User.” More in this post.
Set Up Instructions
Install the latest version from the AppExchange.
Make sure My Domain is set up. Instructions here from Trailhead.
Create a Site
- (Setup -> User Interface -> Sites and Domains -> Sites)
- Create a new Site.
- If you don’t have a Site domain, you’ll need to set one up. You may want to use the same domain as your “My” domain.
- Label: Make the label the name of your organization or whomever the confirmation email should appear from. I will put “Ugly Dog Adoption Agency” and the unsubscribe confirmation email will appear from “Ugly Dog Adoption Agency Site Guest User.” [UPDATE: You can override this! Read this post.]
- Site Name: Unsubscribe (so internally you know what this is about).
- Site Contact: Defaults to your user.
- Click Active.
- Active Site Home Page: select the Visualforce page Unsubscribe.
- The default web address should be blank.
- Save.
Modify the Site Guest User
- Click on the button Public Access Settings at the top.
- Give the Site Guest user access to the Visualforce page UnsubscribeFinish:
- Click on Visualforce Page Access then Edit.
- Add the Visualforce Page UnsubscribeFinish to the Enabled Visualforce Pages list.
- Save.
- Go back to the main page for Sites.
- In the top section of the page under “What is a Site?” look for the box that says “Your Salesforce site domain is” and copy the value there for the next step for when you modify the Custom Metadata Type.
Modify the Custom Metadata Type
- In Setup, search for and click on Custom Metadata Types.
- Click Manage Records to the left of Unsubscribe Link.
- Click the record Unsubscribe.
- In Site Domain, paste in the site domain you created earlier.
- In Our Organization, type in the name of your organization or company. This will appear in the unsubscribe link and the flow screens.
- In Comma Separated Email List make a list of email addresses you’d like to receive custom error messages when the Flows have errors. I’d put your own email so you can troubleshoot while you’re setting this up. These are additional emails beyond the emails the system sends with an error.
Field and Object Level Steps
- On the Contact object, edit the field Unsubscribe Link. Change the Field Label to Unsubscribe Link Contact and the Field Name name to Unsubscribe_Link_Contact. (See the picture below). Give users visibility to this field who need to send commercial or promotional email out of Salesforce.* See Lightning Email Templates section below.
- On the Lead Object, edit the field Unsubscribe Link. Change the field Label to Unsubscribe Link Lead and the Field Name to Unsubscribe_Link_Lead. Give relevant visibility to this field.*
- Give visibility to the Unsubscribe__c object and its fields for anyone tracking the frequency of unsubscribes.
Test It Out
- In your sandbox, make sure Email Deliverability is turned on.
- Go to setup. Search for “Deliverability.”
- Set the access level to “All email.”
- Be very careful if you are using a sandbox with real data – do you have any automated processes that are now going to start firing off emails like crazy? Remember to turn off email deliverability when you’re done testing.
- Optional: Edit your Contact and Lead page layouts.
- Add the Email Opt Out field.
- Add the Unsubscribe related list. You may want to add other fields here like Unsubscribe Email, Created Date, Status.
- Create a contact with your email address.
- Send a test email.
- Send an email to that contact and insert the Unsubcribe Link merge field into an email. Make sure the contact has “Email Opt Out” unchecked.
- When you click the link it should look like this.
The next page should look like this.
- Look for that confirmation email.
- Open the contact record and confirm the following:
- Email opt out is now checked
- There is a new related Unsubscribe record and Status = “Unsubscribed.”
Success!
Email Templates
The Unsubscribe Link formula fields only work in Lightning Templates. As of Spring ’21, you can use Lightning Templates in all automation. I’ve included the code below for using the Unsubscribe Link with classic email templates.
I created two fields on Contact and Lead named the same thing, Unsubscribe_Link__c. That is causing confusion with Lightning templates that list the fields as {{{Recipient.Unsubscribe_Link__c}}}. So first of all, I’m sorry! And I will fix it in the next version. I highly suggest that you rename the Unsubscribe Link fields to be object specific to keep things clear. The steps to do so are outlined above.
Classic Email Templates
If you need to or want to use Classic email templates, you can! Get the classic HTML and Visualforce templates here. Unfortunately, the Unsubscribe Link merge fields don’t work in Classic so you need to use templates.
How to Uninstall the Package
If you have any Unsubscribe__c records from using this package, you’ll lose them by uninstalling.
- Deactivate the Flows: Unsubscribe Link, UnsubscribeContactsv1, UnsubscribeLeadsv1.
- Open the record for your Site.
- Change the “Active Site Homepage” to any other Visualforce page in your system.
- Deactivate the site. Sorry but you are unable to delete Force.com Sites.
- From Setup, search for “Installed Packages” and uninstall.
How to Modify the Confirmation Email Body
In Spring ’21, you can include a Rich Text email in Flows! Hurray! That’s one reason you might want to change the email body. Or you might not like the text “You will no longer receive email from [our organization].”
- Open the Flow “Unsubscribe Link.”
- From Toolbox, Manager, find the formula “PlainTextEmailBody.” This includes another formula that says either the name of your organization or “our organization” depending on what you put in your Custom Metadata Type. Modify your text here. Remember, it’s in the format of a formula.
- You don’t have to use this formula at all. To get a nice Rich Text email, click “New resource” from Toolbox, Manager.
- Choose “Text Template” as your resource type. Here I’ve recreated the formula in a text template, which is much easier to use. Now you can change fonts, add pictures, bullet points, easily have multiple lines, etc. If you aren’t modifying the formula for a rich text feature, there might not be a reason to switch to a text template.
- If you do switch to using a text template instead of the formula, then let your Send Email action know!
- In your canvas, double click on the blue box “Action: Confirmation Email.”
- In the first box labeled “Body,” delete the formula and find the Text Template you just created.
- Save and test out your flow.
How to Remove the Confirmation Email
Troubleshooting
If you’re seeing this error, it’s likely that your “My Domain” was set up to be http and not https. No worries! Just adjust your two formulas called Unsubscribe_Link__c – one on the Contact and and one the Lead objects. Change “https” to “http” in the formulas and somehow that makes it work, and it still runs as https!
Some people need to add the word “Unsubscribe” (capital U) as the default web address on the Site.
If you still need help, and you’ve gone through all the instructions thoroughly a few times, you can email me. Create a contact or a lead in your database with my email address jrymph @ salesforce.com then send me an email that includes your unsubscribe link merge field. Subject: “Please help with unsubscribe link app.” Body: “I have followed all of your very through instructions and still need assistance. [Unsubscribe Link Merge field]. ” (Something like that).