Unsubscribe Link

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.

Image of five star review from AppExchange. Title of review: Great solution - easily modified for other objects. Body of review: Was looking for a solution to add an unsubscribe link to survey invitations. Implementation of this solution was super easy thanks to the extensive documentation. Very easy to manipulate to work for any object with a contact lookup!

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.
This image has an empty alt attribute; its file name is SiteDomain.jpg

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 EmailCreated DateStatus.
  • 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.
This image has an empty alt attribute; its file name is applefence.png

The next page should look like this.

Image of text that says: "Thank you. You have successfully unsubscribed. You will receive a confirmation email shortly."
  • 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.
  • 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.

With this error, make sure you have given the Site Guest User access to the Visualforce page Unsubscribe Finish. See the “Modify the Site Guest User” section above.

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).

Published by

JessieRymph

Jessie is Success Content Specialist at Salesforce.org. All opinions expressed on this blog are her own or those of the contributors. For twelve years, she has specialized in CRM, email marketing and fundraising platforms. Jessie co-led the Seattle Salesforce Non-Profit User Group in 2015-2016. She's working on writing her first novel.

64 thoughts on “Unsubscribe Link”

  1. This is a slick package and meets almost all of our needs. Question: do we have any editorial control over the language used in the link? Our marketing people noted that it refers to “all email” and we’d prefer to edit that slightly. Is that possible?

    1. Thanks and great question! To edit it the language, open the Unsubscribe Link field on the contact object and the Unsubscribe Link field on the lead object. You’ll find a formula that includes the language. Let me know if you need more help!

      1. Perfect, thank you! A follow-up question: is it possible to stop sending the unsubscribe confirmation email?

      2. Yes, it is. It’s an unmanaged package so you can do whatever you want. I need to write up instructions for how to do it though. The gist is to open the Unsubscribe Link Flow, remove the action called Confirmation Email, and then edit the Visualforce page called “Unsubscribe Finish” to remove the text about the confirmation email.

      3. Instructions would be welcome, thanks again. And thanks for being so responsive…this is my first time dealing with anything related to Salesforce Labs and I wasn’t sure what to expect. You’re The Queen!

      4. Hi! I added an instructional video to the post on removing the confirmation email. Happy weekend.

      1. Will definitely do, let me get it running in prod then will pop back in here and post a review.

    1. Quick questions

      We are looking to add ‘Unsubscribe’ link in our Salesforce emails. We have below types of emails:

      – Quick texts to send quick emails to prospects if they didn’t pick the follow up call and other use cases
      – Docomotion emails to send Memo of sale and other relevant documents
      – Automated emails triggered through Process Builder

      Questions:
      – Can this package be utilised for all of the above mentioned email types?
      – If yes, and if a customer chooses to Unsubscribe from ‘automated email’ will he also be unsubscribed from Quick Text emails and emails we are sending from Docomotion package?

      1. Hello! It does not work in quick text unfortunately. I don’t know what Docomotion is. It does work with process builder. See the section about Email Templates to see how to set up both types of templates.

  2. Hi JessieRymph,

    We have successfully deployed your app on our SF in English. However we need to create the same solution for another language, so our users can select a different mergefield in order to trigger the unsubscribe text (and confirmation screen) with the translated text.

    I am able to edit the formula and flow to change the translation, duplicate the fields and flow, however can you guide me on how to link the new mergefield to call on the new flow?

    1. Hey Jason! Great question. The flow is launched in the visualforce page Unsubscribe and ends at the vf page UnsubscribeFinish.
      Clone those visualforce pages. Let’s say you call them UnsubscribeMandarin and UnsubscribeFinishMandarin.
      Let’s say your new Flow is called UnsubscribeMandarinFlow
      In UnsubscribeMandarin (vf page), change line 6 to read

      Change the text in UnsubscribeMandarinFinish from English to the other language.

      Add new UnsubscribeLinkMandarin Formulas: copy the Unsubscribe_Link__c formulas on Contact and Lead, but change this line
      +"/Unsubscribe?recordId="+ CASESAFEID(Id) +"&Email=" +
      to
      +"/UnsubscribeMandarin?recordId="+ CASESAFEID(Id) +"&Email=" +

      I’m pretty sure I got everything! Let me know how that goes!

      1. Hi Jessie,

        I have followed through with your instructions. However, when the unsub link is clicked and the new visualforce page is referenced, it gives me this error:

        Authorization Required – you must first log in or register before accessing this page. If you have forgotten your password, click Forgot Password to reset it.

        I saw this article and double checked my visualforce name as well as the formula reference. It all seems to be in order. Would you have any advise on what may cause this?

        Thanks!

  3. I’m also getting the “your connection is not private” notification after clicking on the link (i.e. when testing it out), thus preventing leads to actually opt out. Looks like other users have encountered this problem as well. Any help in how to fix this problem?

  4. Also, does this work with list emails or salesforce classic email templates? I can’t seem to get it to work with email templates.

    1. When you activate the domain – it actually creates 2 version. One of them is secure while the other one is No HTTPS. Try adding the word “secure.” in front of “force” so it looks like this: yourorganisationname.secure.force.com

  5. I still for the life of me can’t figure out how to remove the error message when clicking on the link. I looked at JB’s post and to be honest it makes no sense. I don’t understand when he says: “I just changed the Subscription_Link__c formula field to produce HTTP rather than HTTPS.”

    Where do you even access that? I can’t find it. Please help. Thank you.

    1. OK! Here’s how to fix it. Open the formula Unsubscribe_Link__c on contact and lead. Change Https to HTTP. Your Site is probably HTTP and not HTTPS. This will result in HTTPS when the link is clicked. It’s still secure. I’ll add some images on the blog for this.

  6. I figured it out based on your description above. Yes, you have to go into Object Manager and then select contact or lead. From there you go to Fields & Relationships and then change the formula. Thank you so much! This will be a super useful tool and appreciate it!

  7. Hello Jessie, Any solve on the Privacy Message issue?
    Everything works great except when the email recipient clicks the link. They get a message page “The Connection Is Not Private” then a bunch of scary text about someone stealing their financial data.

    FACTS tested on mac, pc, and iphone, using both chrome, safari with the same result.

      1. That’s Fantastic! Never ever would have figured that out without you! Thanks…I’ll work my way over to the app store to leave a review now!

  8. Hi Jessie!
    Need some help please – we are receiving an error message on the unsubscribe finish page “An unhandled fault has occurred while processing the flow. Please contact your system administrator for more information” and we would expect this to be accompanied by an error email, but this has not come through to our org-wide error email address; and it’s making it difficult to debug!

    We looked at the flow for contacts and it all makes sense (we even added a couple of extra opt out fields) plus, it works in debug mode.

    We also looked at the fault flow and noticed that it references an unsubscribe object – which has no records on error (or completion we assume; but we haven’t had a successful one yet)

    We’ve looked at the visualforce page access for the guest user. We did turn on flow access permission for guest user too. Although we can’t select this particular flow.

    Can you please help us debug and get this excellent app working, from what we can see so far it’s going to work wonders for our org!

    Thanks, Alex and Charles (Salesforce Consultant)

      1. Hi Jessie.

        To help Alex out, I’m trying it out on my own org, and have a couple of minor issues.

        In the instructions, under Field and Object Level Settings, we’re told to change the “Contact.Unsubscribe Link” field to “Unsubscribe Link Contact” and “Unsubscribe_Link_Lead__c”.
        Problem 1: the system won’t let you add __c to your API Name 😣 I suggest you remove that from the API name to enter
        Problem 2: Should it be “Unsubscribe_Link_Contact” instead of ending in _Lead ? it’s a field on the Contact object, after all.

      2. Yes, I am very sorry for the confusion here. I have updated the instructions above. You should not add __c to the name yourself as the system will do that for you. And yes, you should have the lead field with “Lead” in it and the Contact field with “Contact” in it. Thank you very much for your help!! These are new instructions that I added in recently, and obviously they needed some adjusting!

  9. Hi,

    I was wondering if this allows us to set certain preferences ie if someone wants to unsubscribe to this list but we give them an option to remain on another list, is there a preference section like this so they can click unsubscribe or remain on another list?

    Also, can this be replicated for another function such as if we created a link that says “click if not interested” so someone clicks this link it removes them off this campaign but still keeps them on our genera mailing list?

    Kind regards,

    Jon

    1. Hello! This is an unmanaged package so you can open it up and do whatever you want to with it. The built in functionality checks the “Email Opt Out” box on all records with the email address and creates a record of the custom object Unsubscribe Link. So it would be possible to add check boxes to the flow screen for different campaigns, then delete their campaign member record to that campaign inside the Flow.

  10. Hey Jessie. I got it to work! Had som hassle with the https and secure.force.com work around. But in the end it now works. 🙂

    I have one question though to make the functionality even more seamless. I will be making this functionality available to my org and want them all to make sure this link is added to their list e-mails. However this would require them to “remember” to add the unsubscribe merge field in all their emails and templates. SO there is a risk here.

    I would like to add this merge field to an e-mail footer along with our privacy statement that will always be added to list or mass email from sales cloud. That way it is a no-brainer. BUT the e-mail footer does not support merge fields. Are you able to help me with a solution or workaraound?

    Thanks!

    Kind regards
    Jan Eric (SF Admin newbee)

    1. This is a great question and I don’t know how you would do it. The link requires merge fields!

  11. Hi Jessie! We have templates that we use with “block boxed” warnings from the FDA so ideally we’d like to change the hyperlink text from blue to white so that it is more visible within the html emails. I haven’t any luck with doing it directly in the template and I am thinking it may need to be done directly in the Contact/Lead Custom Fields. Thoughts on how to accomplish this? Thanks so much!

  12. Hi, thank you, your solution works perfectly for us. How can i Cancel the Unsubscribe for contact/lead? thanks again.

    1. If you want to resubscribe them, uncheck the email opt out box. You may need to give your profile permission to do that. You can also delete the unsubscribe (custom object record) but that doesn’t impact anything – it’s just for reporting

  13. Hi Jessie,

    Can you email me and help me with it, The link keeps coming up with an error everytime testing it out.

  14. Hi Jessie,
    I have installed the latest version 2.2 and tried to setup the sites and domain. The domain is set up but can’t see “sites” in my Salesforce setup. Is there any workaround?
    Thanks.

      1. It’s Professional Edition. Does it only compatible with Enterprise or unlimited edition?

      2. Sorry! it works with enterprise, unlimited, developer and performance

  15. Hey Jessie, first of all, thank you for this.

    I’m trying to fully translate all text and prompts to spanish, already modified the unsubscribe URL (Contact formula field), confirmation email body (flow “PlainTextEmailBody” formula and “Confirmation Email” Action) and the “UnsubscribeFinish” visualforce page text but I’m having trouble finding where to edit the site’s unsubscribe prompt (where the “Next” button is). Any help?

    Cheers

  16. Hi Jessie, Thank you for this great app!
    I’ve installed it in one of our sandboxes. It works perfectly well, but when the user clicks “next” the Unsubscribe Finish page does not show up. Instead it says that I need authorization (You have to login oder register to access this site). However, I receive the confirmation email and the field email opt out is updated. Can you help me?

    1. Hey Christina – I am about to publish a new version of the app so I’d suggest trying it. Go here.
      You can uninstall the version you have by following instructions on this page. This new version hasn’t gone through Salesforce security review, fyi.
      If you don’t want to uninstall, make sure your site is Active.
      You might have missed this step:
      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.

      1. Actually, I missed the step to give the Site Guest User access to the Visualforce page Unsubscribe Finish. Now it works. I will also try the new version of the app.
        Thank you very much.

      2. If you are all set up with 2.2, there is no need to try the newest version. The improvements are in the set up. Thanks for trying the app!

  17. Hey Jessie,

    I did the setup as it was mentioned in the video above. I was able to get the Email opt out field updated once I click the link but even after that when I try to send an email by the email component to the Email address, its getting sent.

    Thanks

    1. Thanks for asking. You are saying that from a contact record, you can still email someone after “email opt out” is checked? Does a pop up appear saying “This person has opted out of commercial email. Send anyway?” You should not be allowed to email them by a list view email, but emails sent via workflow or process builder will go anyway. I will clarify this on the blog.

  18. Thank you so much for this – I have tested and deployed 2.2 into our production org now and we are ready to start using the link in our emails through Salesforce. However, some users still send emails from Outlook and then log the email into Salesforce on send. I was just wondering if there is a way to add the unsubscribe link into an Outlook footer. Thanks.

  19. Hi Jesse, this page has a link at the top “Get Unsubscribe Link 3.4 and instructions here” but that page only has URLs to install package version 3.1, and the page text is also about 3.1. Are there instructions and a package for 3.4? Thanks Richard

  20. Hello, I followed your instructions to create a new site, but I am not able to create a new Site and I am getting an error message telling me that the site is already in use.

Leave a Reply