When your business interacts with different employees or departments within a single organization, or when you have forms on your website (such as for downloading a whitepaper), you often create multiple contacts from the same email domain. Associating these contacts with their account can help track interactions, streamline communication efforts, and gain a more comprehensive view of business relationships. However, manually searching for and associating records can be quite a hassle. But don't worry!
Using functions, you can automatically associate contacts with their respective accounts based on their email domains. For instance, when a new contact record with the email "john.smith@acme.com" is created, it will be automatically linked to the account record whose website is www.acme.com. Read on to learn more.
Permissions and availability
- Users with the Manage Extensibility permission can create connections and write custom functions.
- Users with the Manage Automation permission can create and update workflow rules.
- Users with the Manage Sandbox permission can manage the sandbox.
Requirements
- Create a Zoho OAuth connection with the required scopes for your Zoho CRM, as detailed in the "Create Connection" section below. Learn more
- Create a workflow rule for the Contacts module that will trigger a custom function every time a contact is created or edited in your CRM account. Learn more
- Write a custom Deluge function to associate contacts with their accounts and link it to the workflow rule. Learn more
- Test the workflow rule in a sandbox before deploying it in your production environment. Learn more
Create a connection
Follow the steps below to create an OAuth connection in your Zoho CRM account:
- Navigate to Setup > Developer Space > Connections.
- Click Create Connection.
- Select Zoho OAuth under Default Services.
- Specify a Connection Name.
You must enter this name in the code snippet below. - Select the following Scopes to request access:
- ZohoCRM.modules.all
- ZohoSearch.securesearch.READ
- Click Create and Connect.
- Click Connect, then click Accept to confirm authorization of access for the scopes requested by the client.
Create a workflow rule
Follow the steps below to create a workflow rule in your Zoho CRM account:
- Navigate to Setup > Workflow Rules > +Create Rule.
- Select the Module as Contacts from the drop-down list.
- Provide a name for the rule. For example: "Associate contacts with accounts by email domain".
- Add a description, if required, then click Next.
- In the Execute this workflow rule based on section, choose Record Action, then select Create or Edit from the drop-down and click Next.
- In the Which contacts would you like to apply the rule to? section, select All Contacts and click Next.
- Under Instant Actions, select Function and Write your own.
- Provide a name for the function, as well as a description, if necessary.
- In the Deluge Script Editor, do the following:
- Copy and paste the code provided below.
- Click Edit Arguments.
- Choose Contacts - Contact Id, then name it contactId.
- Click the + icon to add more arguments.
- Choose Contacts - Email, and name it email.
- Click Save & Execute Script.
- Click Save on the workflow rule page.
The code
if(!email.isNull())
{
//Get the domain from the email
emailDomain = email.getSuffix("@");
//Search for the website field that matches the email domain
searchCriteria = "(Website:equals:" + emailDomain + ")";
searchAccount = invokeurl
[
url :"https://www.zohoapis.com/crm/v7/Accounts/search?criteria=" + zoho.encryption.urlEncode(searchCriteria)
type :GET
connection:"crmconnection"
];
info "Search Account : " + searchAccount;
if(searchAccount!=null)
{
//Get the account ID from the results
accountId = searchAccount.get("data").get(0).get("id");
//Prepare Map
updateMap = Map();
updateMap.put("Account_Name",{"id":accountId});
//Update contact and map it with account
updateResponse = zoho.crm.updateRecord("Contacts",contactId,updateMap);
info updateResponse;
}
}
Notes
- Replace "connectionname" with the name of the connection you specified while creating the connection (see the Create a connection section above).
- Make sure to use the accurate API names for their corresponding fields (e.g., "Website") in the code snippet. Learn more
- The function won't connect existing contacts to their respective accounts unless they're edited.
Tips
- Ensure that the email field is mandatory for contacts to prevent them from being orphaned when an account exists.
- Set the website's field to unique to avoid creating duplicate account records.
Test the solution
- Navigate to Contacts > + Create Contact.
- On the Contact Details page, enter the required details, including Email, and click Save.
Note: Enter an email address that includes the domain name of the account's website after the "@" symbol.
The workflow rule will be triggered. - Check whether the contact got associated with the account whose website field contains the email's domain.
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
- ModuleContacts
- Trigger PointWorkflow Rule
- EditionEnterprise and above
- ComplexityHigh
- Implementation Time60 minutes

Looking for a custom solution?
Contact us, we will help enhance your productivity at lightning speed.
SUBMIT REQUEST