Businesses often need to duplicate leads in their CRM for various reasons, such as when a lead expresses interest in multiple products handled by different sales teams or needs reassignment to another region or entity. In such situations, salespeople often clone the lead to create separate sales opportunities and targeted follow-ups. While your CRM allows you to clone a lead record, it does not transfer their attachments, making it difficult to manage key information. For example, a car manufacturer may want to clone a lead and assign it to multiple dealerships to improve conversion, but need to manually transfer the documents related to the lead's trade-in vehicle. What if you could clone a lead while retaining specific field data and attachments from the cloned record?
Our low-code tools can come in handy in this scenario. A custom button powered by a function can help you clone a lead record and its attachments. Continue reading to learn how to accomplish this task in less than 30 minutes. You can add this button to the Leads detail view page in any preferred order.
Permissions and availability
- Users with the Manage Extensibility permission can create connections and write custom functions.
- Users with the Modules Customization permission can create custom buttons.
- Users with the Manage Sandbox permission can manage the sandbox.
Requirements
- Create a Zoho OAuth connection with all the scopes for your Zoho CRM account, as detailed in the "Create Connection" section below. Learn more
- Create and link the button with the custom function, as detailed in the "Create Button" section below. Learn more
- Test the function in a sandbox before deploying it in your production environment. Learn more
Create a connection
The first step is to create an OAuth connection in your Zoho CRM account.
- Go to Setup > Developer Space > Connections.
- Click Create Connection.
- Select Zoho OAuth under Default Services.
- Specify a Connection Name.
You must enter this name in the code snippet below. - Select the following Scopes to request access.
- ZohoCRM.modules.all
- Click Create and Connect.
- Click Connect, then click Accept to confirm authorization of access for the scopes requested by the client.
Create a button
The next step is to add a custom button that, when clicked, clones the lead record along with its attachments.
- Go to Setup > Customization > Modules and Fields > Leads > Buttons > Create New Button.
- Provide a name for the button. For example: "Clone Lead".
Add a description (optional). - Choose the layout(s) where you want the button to be placed.
- Specify the button's placement as In Record and its position on the page as Details.
- Select the action to be performed as Writing Function.
- Provide a name and display name for the function and click Create.
- In the Deluge script editor, do the following:
- Copy and paste the code provided below.
- Click Edit Arguments.
- Enter the name as leadId, select the value as Leads - Lead Id, then click Save.
- Save the function.
- Select the profiles who can view this custom button.
- Click Save.
The code
leadDetails = zoho.crm.getRecordById("Leads",leadId.toLong());
mp = Map();
mp.put("Last_Name",ifnull(leadDetails.get("Last_Name"),""));
create = zoho.crm.createRecord("Leads",mp);
info create;
newLeadID = create.get("id");
relatedrcords = zoho.crm.getRelatedRecords("Attachments","Leads",leadId.toLong());
attachid = List();
for each ele in relatedrcords
{
attachementId = ele.get("id");
fileName = ele.get("File_Name");
downloadFile = invokeurl
[
url :"https://www.zohoapis.com/crm/v2/Leads/" + leadId + "/Attachments/" + attachementId
type :GET
connection:"connectionname"
];
info downloadFile;
if(fileName.contains(".html"))
{
downloadFile = downloadFile.toFile(".html");
}
else if (fileName.contains(".txt") )
{
downloadFile = downloadFile.toFile(".txt");
}
resp = zoho.crm.attachFile("Leads",newLeadID,downloadFile);
info resp;
}
openUrl("https://crm.zoho.com/crm/org167693575/tab/Leads/" + newLeadID,"same window");
return "Lead cloned successfully";
Notes
- Replace "connectionname" with the name of the connection you specified while creating it in your CRM (see the Create a connection section above).
- Make sure to use the accurate API names for their corresponding fields (e.g., "Last Name") in the code snippet. Learn more
- As the API URLs differ for each data center, you should identify your account's data center and use the corresponding domain in the url. For example, for India, use https://www.zohoapis.in/crm.
- Upon cloning, the function transfers only the lead's last name and attachments to the cloned record. You can customize the code to include additional fields as needed.
- The function converts HTML and text file attachments to .html and .txt format and transfers them to the cloned record.
Tip
- Configure and test the function in a sandbox to ensure that further development doesn't disrupt your production environment.
Test the solution
- Click the Leads tab.
- Open the lead record you want to clone and click the new button you added to the top-right area.
The new cloned lead will open in a new tab. - Check whether the lead information—such as the last name and attachments—was transferred to the cloned lead.
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 PointCustom Button
- EditionEnterprise and above
- ComplexityHigh
- Implementation Time60 minutes

Looking for a custom solution?
Contact us, we will help enhance your productivity at lightning speed.
SUBMIT REQUEST