Identify new and existing customers

Classify accounts as new or existing customers based on the number of closed-won deals associated with them in your CRM.

Businesses thrive on relationships, and recognizing new and existing customers can be the key to turning a one-time sale into a repeat transaction. However, as your business grows and you close more deals, it can become challenging for your sales team to differentiate between new and returning customers. For example, a personalized onboarding process can transform a one-time buyer into a loyal customer. Likewise, tailored recommendations and loyalty rewards demonstrate to existing customers they’re valued.

A practical method to categorize both new and existing customers is by the number of closed-won deals associated with each account. An account is classified as a new customer if it has just one closed-won deal. Conversely, existing customers are those with two or more closed-won deals. While a rollup summary field can count closed-won deals, it does have certain limitations. This is where a custom function coupled with a workflow rule offers a more flexible alternative.

Using functions, you can automatically count all closed won deals associated with an Account and categorize that account as either an existing or new customer in its custom picklist field based on the defined threshold of won deals. Then, connect the function to a workflow rule that triggers every time a deal is marked as won. Read on to learn more.

Permissions and availability

  • 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 Extensibility permission can create custom functions.
  • Users with the Manage Sandbox permission can manage the sandbox.

Requirements

  • Add a Number field to the Accounts module. This field will hold the number of closed won deals associated with each account. Learn more
  • Add a Picklist field to the Accounts modules. This field will reflect the appropriate value based on the number of deals won.
  • Create a workflow rule for the Deals module that triggers the custom function whenever a deal is marked as "Closed Won". Learn more
  • Write a custom Deluge function that, based on the number of closed won deals associated with an account, categorizes them as either existing or new customers. Learn more
  • Test the workflow rule in a sandbox before deploying it to your production environment. Learn more

Add custom fields

The first step is to add the custom picklist and number fields to the Accounts module.

  1. Navigate to Setup > Customization > Modules and Fields.
  2. Click the Accounts module to open the layout editor, then do the following:
  3. Drag and drop the Picklist field from the New Fields tray to the layout.
  4. Name the picklist field (e.g., "Customer Status"), enter the options (e.g., "New" and Existing"), then click Done.
  5. Again, drag and drop the Number field from the New Fields tray to the layout.
  6. Name the number field (e.g., "Total Deals Won"), define its properties, then click Done.
  7. Once you have finished, click Save and Close.

Create a workflow rule

The next step is to create a workflow rule that triggers the custom function whenever a deal is marked as won.

  1. Navigate to Setup > Workflow Rules and click + Create Rule.
  2. Select Deals from the module dropdown list.
  3. Provide a name for the rule. For example: "Classify accounts as new or existing".
  4. As an optional step, you can add a description. Afterwards, click Next.
  5. In the Execute this workflow rule based on section, do the following:
    1. Choose Record action, and then select Edit from the dropdown.
    2. Choose Specific field(s) gets modified from the dropdown, then enter the condition "When <Stage> is modified to <the value> <Closed Won>".
    3. Click Next.
  6. In the Which deals would you like to apply the rule to? section, select All Deals, then click Next.
  7. Under Instant Actions, select Function and 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, name it Id, and click Save.
    4. Click Save & Execute Script.
  10. Click Save on the workflow rule page.

The code

Code Copied
rel_recs = zoho.crm.getRelatedRecords("Deals", "Accounts", Id);
info "rel_recs : " + rel_recs;
count = 0;
mp = map();
if(rel_recs.size()>0)
{
for each rec in rel_recs
{
    stage = rec.get("Stage");
    info "stage : " + stage; 
    if(stage == "Closed Won")
    {
        count = count + 1;
    }
}
info "count : " + count; 
// Update the total deals won
mp.put("Total_Deals_Won", count);

// Set customer status based on the count
if(count >= 2)
{
    mp.put("Customer_Status", "Existing");
}
else
{
    mp.put("Customer_Status", "New");
}
info "mp : " + mp; 
upd_rec = zoho.crm.updateRecord("Accounts", Id, mp);
info upd_rec;
}

Notes

  • Make sure to use the accurate API names for their corresponding fields in the code snippet (e.g., Customer Status). Learn more
  • This function executes the code block only if there is at least one deal associated with the account. Therefore, accounts without any deals will not have either field updated.
  • The code above is an example of how to automatically classify accounts as either new or existing based on the number of closed-won deals associated with each account. You can use this code to classify records in any module—including custom modules—by updating the module name and relevant 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 Deals module.
  2. Open the deal record that you want to update as won.
  3. On the Deal Details page, update the stage as Closed Won, then save your changes.
    The workflow rule will be triggered.
  4. Click on the Account Name associated with the deal to view its details.
  5. On the Account Details page, verify if the Total Deals Won field displays the accurate number of closed-won deals and whether the Customer Status field reflects the appropriate value based on that count.

Idea

If you wish to update the customer type information in your existing account records, follow the steps below:

  1. Add a dummy checkbox field in the Accounts module (e.g., Mass Update).
  2. Add a workflow rule for the Accounts module that triggers when the dummy checkbox field is updated.
  3. Ensure the Repeat this workflow whenever an Account is edited option is checked.
  4. Set the workflow rule to apply to all accounts.
  5. Under Instant Actions, select the pre-saved function and save the rule.
  6. Navigate to the Accounts module, select the accounts whose customer type information needs to be updated in bulk, and mass update the checkbox field to trigger the workflow and its associated function.
  7. Check whether the selected accounts have had their Total Deals Won and Customer Status fields updated with the correct values.

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
  • ComplexityMedium
  • Implementation Time30 minutes

Features used in the solution

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