Sync contacts with account data

Auto-update contact records whenever their account details change to ensure accuracy and consistency while saving time through seamless workflow automation.

It's quite common that businesses need to maintain consistency across related records in their CRM application. A typical requirement is to update all contacts associated with an account whenever information at the account level changes. For instance, when a company changes its industry type, communication preferences, or any other key classification, this information often needs to be reflected across all related contact records to ensure data consistency and accurate segmentation.However, doing this one contact at a time would be time-consuming and error-prone, especially for accounts with numerous associated contacts. But now there's a solution!

To spare you the effort of manual work, you can create a workflow rule linked to a custom function that updates all related contacts whenever specific fields are modified in the account record, which ensures data integrity and saves your team's valuable time. Read on to learn more.

Permissions and availability

  • Users with the Manage Extensibility permission can create connections and write custom functions.
  • Users with the Modules Customization permission can add custom fields.
  • 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 CRM connection with the required scopes as detailed in the "Create Connection" section below. Learn more
  • Add a Picklist field in the Contacts module. This field will hold the account type value from the related account. Learn more
  • Create a workflow rule for the Accounts module that triggers when the Account Type field is modified. Learn more
  • Write a custom Deluge function that automatically updates a contact's type based on the account type of its associated account, and attach it to a workflow rule. Learn more
  • Test the solution in a sandbox before deploying it to your production environment. Learn more

Create a connection

First, create a new connection in your Zoho CRM account.

  1. Go to Setup > Developer Hub > Connections.
  2. Click Create Connection.
  3. Select Zoho CRM under Default Services.
  4. Specify a Connection Name.
    You will need to enter this name in the code snippet below.
  5. Select the following scope to request access:
    • ZohoCRM.modules.ALL
  6. Click Create and Connect.
  7. Click Connect, then click Accept to confirm access authorization for the scope requested by the client.

Add a custom field

Next, add a custom picklist field to the Contacts module.

  1. Navigate to Setup > Customization > Modules and Fields.
  2. Click the Contacts module to open the layout editor.
  3. Drag and drop the Picklist field from the New Fields tray to the desired section of the layout.
  4. Name the picklist field (e.g. "Contact Type"), define its properties as required, and click Done.
  5. Once you have finished, click Save and Close.

Create a workflow rule

Next, you need to write and connect a custom function with a workflow rule.

  1. Navigate to Setup > Workflow Rules > +Create Rule.
  2. Select the module as Accounts from the dropdown list.
  3. Provide a name for the rule. For example: "Update account type in contacts".
  4. Add a description, if required, 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 dropdown.
    2. Check the box for Repeat this workflow whenever a account is edited.
    3. Choose Specific field(s) gets modified from the dropdown, then enter the condition "When <Account Type> is modified to <any value>".
    4. Click Next.
  6. In the Which accounts would you like to apply the rule to? section, select All Accounts, then click Done.
  7. Under Instant Actions, select Function, then Write your own.
  8. Provide a Name for the function, as well as a description, if necessary.
  9. In the Deluge Script Editor, do the following:
    1. Copy and paste the code provided below.
    2. Click Edit Arguments.
    3. Choose Accounts - Account Id and name it accountId.
    4. Click the + icon to add more arguments.
    5. Choose Accounts - Account Type, name it type, then click Save.
    6. Click Save & Execute.
  10. Click Save on the workflow rule page.

The code

Code Copied
response = invokeurl
[
	url :"https://www.zohoapis.com/crm/v8/Accounts/" + accountId + "/Contacts?fields=Owner,Parent_Id"
	type :GET
	connection:"connectionname"
];
info response;
rdata = response.get("data");
if(rdata.size() > 0)
{
	for each ele in rdata
	{
		mp = Map();
		mp.put("Contact_Type",type);
		mp.put("id",ele.get("id"));
		mlist = List();
		mlist.add(mp);
		paramsMap = Map();
		paramsMap.put("data",mlist);
		response = invokeurl
		[
			url :"https://www.zohoapis.com/crm/v8/Contacts"
			type :PUT
			parameters:paramsMap.toString()
			connection:"connectionname"
		];
		info response;
	}
}

Notes

  • Replace "connectionname" with the name of the connection you specified when creating it (see the "Create a connection" section above).
  • Make sure to use the accurate API names for their corresponding fields (e.g., "Contact Type") in the code snippet. Learn more
  • Ensure the contact's picklist field includes all available options from the account.
  • The script above is an example of how to automatically retrieve all contacts associated with a specific account and update their Type field to match the account type. You can use this code for any other related module, such as Leads, by modifying the module name and the fields being updated.

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 Accounts > + Create Account.
  2. Create an account that includes at least one associated contact.
    Note: The Contact Type field for the associated contact should be set to "None".
  3. Navigate to the newly created account and modify the Account Type field to any value (e.g. "Partner").
    The workflow rule will be triggered.
  4. Check whether the Contact Type field for the associated contact is updated to match the account type.
  5. Test other edge cases, including accounts with no contacts, null values, and accounts with many contacts.

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

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

Features used in the solution

ConnectionCustom 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!