Copy leads to a custom module

Automatically copy lead data to a custom module when a picklist value changes to enable seamless tracking and faster engagement without manual effort.

In many business scenarios, organizations need to copy lead information into custom modules for specific tracking or processing purposes. For example, suppose you run a gaming company and have a custom module named Paid Customers. When a lead signs up, you store their information in the standard Leads module. Once they upgrade to a paid plan, you copy their information into the Paid Customers module. However, manually copying record information from the Leads module to custom modules can be time-consuming and error-prone.

What if there were a quick workaround that automatically copies a lead's field information into a custom module without any manual intervention? A custom function can help you do so whenever a lead's picklist value gets updated in your CRM account.

A workflow rule powered by a custom function can help you quickly copy all required fields from the Leads module to a custom module and enable you to engage with them more effectively. 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 permissions can manage the sandbox.

Requirements

  • Create a Zoho CRM connection with the required scope as detailed in the "Create a connection" section below. Learn more
  • Add a custom picklist field to the Leads module. This field will indicate whether the customer is paid or free. Learn more
  • Create a workflow rule for the Leads module that triggers when the value of the picklist field is updated. Learn more
  • Write a custom Deluge function and connect it to the workflow rule to copy lead information into the custom module. Learn more
  • Test the workflow rule in a sandbox before deploying it to your production environment. Learn more

Create a connection

The first step is to create a connection in your Zoho CRM account.

  1. Navigate to Setup > Developer Hub > Connections.
  2. Click CreateConnection.
  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 to the requested scope.

Add a custom field

The next step is to add a custom picklist field to the Leads module.

  1. Navigate to Setup > Customization > Modules and Fields.
  2. Click the Leads 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., "Paid"), enter the options (e.g., "Yes" and "No"), define its properties, then click Done.
  5. Once you've finished, click Save and Close.

Create a workflow rule

The final step is to create a workflow rule and connect it with a custom function.

  1. Navigate to Setup > Workflow Rules > + Create Rule.
  2. Select the Module as Leads from the dropdown list.
  3. Provide a name for the rule. For example: "Copy leads to a custom module".
  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. Uncheck the box for Repeat this workflow whenever a lead is edited option.
    3. Choose Specific field(s) gets modified from the dropdown, then enter the condition "When <Paid> is modified to <the value> <Yes>".
    4. Click Next.
  6. In the Which leads would you like to apply the rule to? section, select All Leads, 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. Enter the name as leadId, and select the value as Leads - Lead Id.
    4. Click Save, then click Save & Execute Script.
  10. Click Save on the workflow rule page.

The code

Code Copied
leadIdLong = input.leadId.toLong();
resp = invokeurl
[
url :"https://www.zohoapis.com/crm/v8/Leads/" + leadIdLong
type :GET
connection:"connectionname"
];
Info resp;
leadDetails = resp.get("data").get(0);
mp = map();
mp.put("Name",ifnull(leadDetails.get("Full_Name"),""));
mp.put("Annual_Revenue", ifnull(leadDetails.get("Annual_Revenue"),""));
mp.put("Billing_City", ifnull(leadDetails.get("City"),""));
mp.put("Billing_Country", ifnull(leadDetails.get("Country"),""));
mp.put("Description", ifnull(leadDetails.get("Description"),""));
mp.put("Fax", ifnull(leadDetails.get("Fax"),""));
mp.put("Industry", ifnull(leadDetails.get("Industry"),""));
mp.put("Employees", ifnull(leadDetails.get("No_of_Employees"),""));
mp.put("Phone", ifnull(leadDetails.get("Phone"),""));
mp.put("Rating", ifnull(leadDetails.get("Rating"),""));
mp.put("Billing_State", ifnull(leadDetails.get("State"),""));
mp.put("Billing_Street", ifnull(leadDetails.get("Street"),""));
mp.put("Billing_Code", ifnull(leadDetails.get("Zip_Code"),""));
mp.put("Website", ifnull(leadDetails.get("Website"),""));
info mp;
listmap = List();
listmap.add(mp);
datamap = Map();
datamap.put("data",listmap);
info datamap;
response = invokeurl
[
 url :"https://www.zohoapis.com/crm/v8/CustomModuleApiName"
 type :POST
 parameters:datamap.toString()
 connection:"connectionname"
];
info response;

Notes

  • Use the accurate API name of the fields used in the code snippet (e.g., "Full Name"). Learn more
  • Customize the field API name mapping to ensure accurate data transfer between Leads and the custom module.
  • Replace "connectionname" with the name of the Zoho CRM connection (see the "Create a connection" section above).
  • Replace "CustomModuleApiName" with the API name of the custom module to which you'll copy the lead data.
  • Change the URL endpoint to match the data center of your account. For example, https://www.zohoapis.in/... for India.
  • The code above demonstrates how you can automatically copy lead information into a custom module record to ensure data consistency and save valuable time. You can use this code for any other module by modifying the module name and other parameters.

Tips

  • Configure and test the function in a sandbox to ensure that further development doesn't disrupt your production environment.
  • You can associate this function with a custom button to create records in the custom module whenever required. Just remember to include a return statement at the end.

Test the solution

  1. Navigate to the Leads module.
  2. Open a lead record to view its details.
  3. Change the Paid picklist field from "No" to "Yes", and then click Save.
    The workflow rule will be triggered.
  4. Navigate to your custom module (e.g., "Paid Customers").
  5. Check whether a new record has been created containing the details of the lead record. Verify that all the specified fields in the code snippet have been copied correctly.

Idea

Businesses don't always transfer data from standard modules to custom ones. What if you need to copy data from one custom module to another? In that case, you can use the code snippet below in a custom function.

Code Copied
resp = invokeurl
[
url :"https://www.zohoapis.com/crm/v8/CustomModule1ApiName/" + CustomModuleId
type :GET
connection:"connectionname"
];
Info resp;
CustommoduleDetails = resp.get("data").get(0);
createMap = map();
createMap.put("Name", ifnull(CustommoduleDetails.get("Name"),""));
createMap.put("Owner", ifnull(CustommoduleDetails.get("Owner"),"").get("id"));
createMap.put("Phone", ifnull(CustommoduleDetails.get("Phone"),""));
createMap.put("Email", ifnull(CustommoduleDetails.get("Email"),""));
listmap = List();
listmap.add(createMap);
datamap = Map();
datamap.put("data",listmap);
info datamap;
response = invokeurl
[
 url :"https://www.zohoapis.com/crm/v8/CustomModule2ApiName"
 type :POST
 parameters:datamap.toString()
 connection:"connectionname"
];

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

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