View key deal metrics in accounts

Record and view your customers' key deal-related metrics in their corresponding account records in your CRM.

Tracking key deal-related metrics of your customers can help tailor your sales strategies. For example, understanding the total number of deals created, the number of deals won, revenue from won deals, and the number of deals lost can help you identify opportunities for upselling, cross-selling, and other potential engagements. While a rollup summary can calculate the aggregate values from the account's related deal records, it doesn't count records in a blueprint process, hindering real-time insights into account performance.
 

As this scenario is a special requirement for some businesses, we support it through a custom function coupled with a workflow rule. The function can update the number of deals created, deals won, revenue from won deals, and deals lost in their respective custom fields of an account as deals are created or modified. Additionally, since the custom function considers records that haven't exited a blueprint, it ensures real-time updates to the numbers. Continue reading to learn how to accomplish this in less than 30 minutes.

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 four Number fields in the Accounts module. The number fields will hold the total number of deals created, the number of deals won, the total revenue from the won deals, and the number of deals lost. Learn more
  • Create a workflow rule for the Deals module that triggers every time a deal is created or modified. Learn more
  • Write a custom Deluge function and link it with the workflow rule to update the custom fields added to the account records. 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 adding the custom Number fields to the Deals module.

  1. Navigate to Setup > Customization > Modules and Fields.
  2. Click the Deals module to open the layout editor.
  3. Drag and drop four Number fields from the New Fields tray to the layout.
  4. Name the number fields as indicated below and define their properties as required.
    • Total Deals
    • Deals Won
    • Deals Lost
    • Total Sales
  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 Deals from the module dropdown list.
  3. Provide a name for the rule. For example: "Display deal metrics in account".
  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 Create or Edit from the dropdown.
    2. Check the box for Repeat this workflow whenever a Deal is edited.
    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
rsp = zoho.crm.getRelatedRecords("Deals","Accounts",id);
sz = rsp.size();
if ( sz > 0 ) 
{
mp = Map();
mp.put("Total_Deals",sz);
amount = 0;
won = 0;
lost = 0;
for each  ele in rsp
{
st = ele.get("Stage");
if (st == "Closed Won" ) 
{
	am = ifnull(ele.get("Amount"),0);
	amount = amount + am;
   won = won+1;
	mp.put("Total_Sales",amount);
   mp.put("Deals_Won",won);
}
if ( st == "Closed lost" ) 
{
lost = lost+1;
   mp.put("Deals_Lost",lost);
}
}
up = zoho.crm.updateRecord("Accounts",id,mp);
info up;
info mp;
}

Notes

  • Use the accurate API name of the custom URL field in the code snippet (e.g., "Total Deals"). Learn more
  • The code snippet does not add to existing field data in increments when deals are created or modified. Instead, it recalculates the numbers every time the function is triggered and updates the field with the newly computed number.
  • The total sales value is calculated by summing the deal amounts from each closed-won deal created for an account.
  • The code above is an example of how to track and record deal-related metrics in the respective fields of an account. You can use this code to track the count of any other field or module 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. Click the Deals tab.
  2. Create a deal record for a specific amount.
  3. Update the deal status to Closed Won and click Save.
    The workflow rule will be triggered.
  4. Check whether the Total Deals and Deals Won fields were updated by one and whether the Total Sales reflects the deal amount.
  5. You can test various scenarios and confirm that the function is working seamlessly.

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

  • ModuleDeals
  • 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!