Changing Ownership of Multiple Related Records concurrently

Business scenario:

Each of us have our strengths and weaknesses. Someone skilled in sales might not necessarily be better in management. It goes to show that in order to successfully run an enterprise, you need an amalgamation of various different talents that work together. Marketing, Sales, Negotiation, Support, Development, etc. All of them have their roles cut out clearly.

As such, lets say there's a guy from the Sales team who takes care of the leads and converting them into deals. Now, that guy has a lot of work to do in converting the lead. Assigning tasks, events, scheduling calls, emails, cases, quotes, purchase orders, etc. He might have to lay the groundwork for the guy who takes care of the negotiation part after the lead is converted. The initial owner of the deal and all the related records with the deal is the Sales guy, but when converted into a deal, shouldn't the ownership change for all of the records? But guess what, changing the deal ownership doesn't change the rest.

But we do have a workaround as you've guessed, since we explained things this far. You can use a function to transfer the ownership for all of the records simultaneously. And this works best when the function is created within a Workflow rule, which can be set to trigger "This rule will be executed when the field Leads Owner is updated to meet the condition(if any)." And there you have it.

 

Getting started with the function:

  1. Go to Setup > Developer Space > Functions > + Create New Function.
  2. Select Automation as Function type and click Next.
  3. Provide a name for the function. Add a description(optional).
  4. Copy the code given below.
  5. Click Edit Arguments.
  6. Enter the name as dealId and select the type as Int.
  7. Enter the name as dealownerid and select the type as Int.
  8. Click Save&Execute Script.
  9. Click Save.
 

The Code:


relatedcases = zoho.crm.getRelatedRecords("Cases", "Deals", input.dealId.toLong());
//info relatedcases;
for each ele in relatedcases
{
update = zoho.crm.update("Cases",ele.get("id"),{"Owner":input.dealownerid});
}

 

Adding to the workflow

  1. Go to Setup > Automation > Workflow Rules.
  2. Click '+ Create Rule'.
  3. Select the Module for which this custom function has to be added and give it a name and a description(optional).
  4. Select "On a record action" in the "When do you want to execute this rule?".
  5. Select "Field Update" and click "Repeat this workflow whenever a record is edited".
  6. Select "Deal Owner" and click Next.
  7. Select the Condition as "All Records".
  8. Select the checkbox "Repeat this workflow whenever a record is edited." and Click Next.
  9. Choose "Function" from Instant Actions.
  10. Select the option "Function" (Created by users from your organization).
  11. Select the required function and click Configure.
  12. Click Save and Associate.
  13. Save the workflow.
 

Note:

  • Change the module name in the code from "Cases" to any other module you want.
  • The above code works only for API V2.0 and not the previous version.
 

Found this useful? Try it out and let us know how it works! If you have questions, do not hesitate to ask! Share this with your team if you find it useful!

Return to Tips