Auto-update email opt-out status

Update the email opt-out field for contacts related to the selected account when its corresponding custom module field matches a specific value.

Respecting customer privacy and preferences is crucial to maintaining a positive relationship with them. If a customer has requested that they be removed from email lists or has marked emails as spam, it's important to opt them out of receiving further emails. CRM has different methods to achieve this, such as an unsubscribe link, manual unsubscribe, consent forms, or using Zoho Campaigns. However, what if you need to stop a contact from receiving emails based on a field value in a custom module? For example, you have a custom module called "Licenses" with a picklist field called "Customer Type." If this field has the "Reseller" value, then you can set the "Email Opt Out" checkbox to true for all contacts associated with the account where the license is assigned. This is where a custom function can come in handy.

Using functions, you can check if a field in a custom module has a specific value. If it does, it updates the email opt-out field of the contacts related to the selected account. Read on to learn more.

Permissions and availability

  • Users with the Modules Customization permission can add custom modules and fields.
  • Users with the Manage Automation permission can create and update workflow rules.
  • Users with the Manage Extensibility permission can create custom functions.
  • Users with the Manage Sandbox permission can manage the sandbox.

Requirements

  • Create a custom module (e.g., Licenses) and add a picklist and lookup fields underneath it. Learn more
  • Create a workflow rule for the Licenses module to update the email opt-out field for contacts associated with the chosen account based on its picklist value. Learn more
  • Write a custom Deluge function and link it with the workflow rule. Learn more
  • Test the workflow rule in a sandbox before deploying it to your production environment. Learn more

Adding a custom module and fields

The first step is creating a custom module and adding the necessary fields.

  1. Navigate to Setup > Customization > Modules and Fields > + New Module.
  2. Enter a name for the module - both the singular and plural forms, then click Done. For example, License and Licenses, respectively.
  3. Drag and drop the Picklist field from the New Fields tray to the layout.
  4. Name the picklist field (e.g., "Customer Type") and add its options as required, including "Reseller", "Customer", and "Vendor".
  5. Drag and drop the Lookup field from the New Fields tray to the layout.
  6. Name the lookup field (e.g., "Account Name"), select Accounts as the Lookup Module, and enter a title (e.g., "License Name") to display in the account record.
  7. Once you have finished, select Done, and then click Save and Close.
Add Custom Field

Create a workflow rule

Follow the below steps to create a workflow rule that updates the email opt-out field.

  1. Navigate to Setup > Workflow Rules > + Create Rule.
  2. Select Licenses from the module drop-down list.
  3. Provide a name for the rule. For example: "Check Email Opt Out for Resellers".
  4. Add a description (optional), then click Next.
  5. In the Execute this workflow rule based on section, do the following:
    1. Choose Record Action, then select Edit from the drop-down.
    2. Check the box for Repeat this workflow whenever a License is edited.
    3. Choose Specific field(s) gets modified from the drop-down, then enter the condition "When <Customer Type> is modified to <any value>".
    4. Click Next.
  6. In the Which licenses would you like to apply the rule to? section, select All Licenses, then click Next.
  7. Under Instant Actions, select Function and Write your own.
  8. Provide a name and description (optional) for the function.
  9. On the Deluge Script Editor, do the following:
    1. Copy and paste the code provided below.
    2. Click Edit Arguments.
    3. Choose Licenses - License Id and name it as licId.
    4. Choose Account Name - Account Id and name it accId.
    5. Click Save & Execute Script.
  10. Click Save on the workflow rule page.

The code

Code Copied
lic = zoho.crm.getRecordById("Licenses",licId);
res = lic.get("Customer_Type");
info res;
if(res.contains("Reseller"))
{
	condetails = zoho.crm.getRelatedRecords("Contacts","Accounts",accId);
	for each  contact in condetails
	{
		ids = contact.get("id");
		update = zoho.crm.updateRecord("Contacts",ids,{"Email_Opt_Out":true});
		info update;
	}
}

Notes

  • Make sure to use the accurate API names for their corresponding fields (e.g., "Customer Type") in the code snippet. Learn more
  • The code above is an example to update the email opt-out field for contacts related to the selected account when its corresponding custom module field matches a specific value. You can use this code for any other module, such as Leads, by modifying the module name and parameters.

Tip

  • Configure and test the function in a sandbox to ensure that further development doesn't disrupt your production environment.

Test the solution

  1. Navigate to the Accounts module.
  2. Select an account record that has one or more contacts linked to it.
    Ensure it has at least one contact whose Email Opt Out field is unchecked.
  3. Under Related Lists, click License Name.
    Remember, this is your title for the Account Name lookup field in the Licenses module.
  4. Click Assign and choose an existing license.
  5. Once chosen, open the license to view its details and set the value of its Customer Type field to Reseller.
    The workflow rule will be triggered.
  6. Check whether the Email Opt Out field was checked for all contacts of the account where the license is assigned.

Did you find this useful? Try it out and let us know how it works. Share this with your team if they'd benefit from it! If you have questions, please don't hesitate to contact us.

More info

  • ModuleCustom
  • Trigger PointWorkflow Rule
  • EditionEnterprise and above
  • ComplexityHigh
  • Implementation Time60 minutes

Features used in the solution

Custom ModuleCustom FieldWorkflow RuleDeluge ScriptSandbox
Story Image

Looking for a custom solution?

Contact us, we will help enhance your productivity at lightning speed.

SUBMIT REQUEST

Developers: Share your solution with our community!