It's a common practice to collect as much information as possible while engaging with your leads. This information gets stored in custom fields, notes, attachments, activities, and standard or custom related lists within your CRM account. When you convert a lead, all of this contextual information must be carried over into its corresponding contact, account, and deal records. However, Zoho CRM's lead conversion process only allows you to carry over a lead's standard, custom field values, and standard related lists, but not the additional information added in the custom related lists. To learn more about standard conversion mapping, refer to Converting Leads.
Using functions, you can convert leads and transfer all important information to their corresponding contact records with the click of a button. 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
Follow the steps below 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
- ZohoCRM.modules.attachments.all Learn more
- Click Create and Connect.
- Click Connect and then click Accept to confirm authorization of access for the scopes requested by the client.
Create a button
Follow the steps below to create a custom button in your Zoho CRM account:
- Go to Setup > Customization > Modules and Fields > Leads > Buttons > Create New Button.
- Provide a name for the button. For example: "Copy lead info upon conversion".
Add a description (optional). - Choose the layout(s) 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 and select the value as Leads - Lead Id.
- Save the function.
- Select the profiles who can view this custom button.
- Click Save.
The code
leadIdLong = input.leadId.toLong();
leadDetails = zoho.crm.getRecordById("Leads", leadIdLong);
AcccountMap = map();
AcccountMap.put(("Account_Name"), ifnull(leadDetails.get("Company"),""));
AcccountMap.put("Annual_Revenue", ifnull(leadDetails.get("Annual_Revenue"),""));
AcccountMap.put("Billing_City", ifnull(leadDetails.get("City"),""));
AcccountMap.put("Billing_Country", ifnull(leadDetails.get("Country"),""));
AcccountMap.put("Description", ifnull(leadDetails.get("Description"),""));
AcccountMap.put("Fax", ifnull(leadDetails.get("Fax"),""));
AcccountMap.put("Industry", ifnull(leadDetails.get("Industry"),""));
AcccountMap.put("Employees", ifnull(leadDetails.get("No_of_Employees"),""));
AcccountMap.put("Phone", ifnull(leadDetails.get("Phone"),""));
AcccountMap.put("Rating", ifnull(leadDetails.get("Rating"),""));
AcccountMap.put("Billing_State", ifnull(leadDetails.get("State"),""));
AcccountMap.put("Billing_Street", ifnull(leadDetails.get("Street"),""));
AcccountMap.put("Billing_Code", ifnull(leadDetails.get("Zip_Code"),""));
AcccountMap.put("Website", ifnull(leadDetails.get("Website"),""));
AccountCreate = zoho.crm.create(("Accounts"), AcccountMap);
info AccountCreate;
newaccountId = AccountCreate.get("id");
ContactMap = map();
ContactMap.put("First_Name", ifnull(leadDetails.get("First_Name"),""));
ContactMap.put("Last_Name", ifnull(leadDetails.get("Last_Name"),""));
ContactMap.put("Mailing_City", ifnull(leadDetails.get("City"),""));
ContactMap.put("Mailing_Country", ifnull(leadDetails.get("Country"),""));
ContactMap.put("Mailing_State", ifnull(leadDetails.get("State"),""));
ContactMap.put("Mailing_Street", ifnull(leadDetails.get("Street"),""));
ContactMap.put("Mailing_Zip", ifnull(leadDetails.get("Zip_Code"),""));
ContactMap.put("Description", ifnull(leadDetails.get("Description"),""));
ContactMap.put("Fax", ifnull(leadDetails.get("Fax"),""));
ContactMap.put("Title", ifnull(leadDetails.get("Title"),""));
ContactMap.put("Email", ifnull(leadDetails.get("Email"),""));
ContactMap.put("Lead_Source", ifnull(leadDetails.get("Lead_Source"),""));
ContactMap.put("Mobile", ifnull(leadDetails.get("Mobile"),""));
ContactMap.put("Phone", ifnull(leadDetails.get("Phone"),""));
ContactMap.put("Secondary_Email", ifnull(leadDetails.get("Secondary_Email"),""));
ContactMap.put("Skype_ID", ifnull(leadDetails.get("Skype_ID"),""));
ContactMap.put("Twitter", ifnull(leadDetails.get("Twitter"),""));
ContactMap.put("Account_Name", newaccountId);
ContactCreate = zoho.crm.create("Contacts", ContactMap);
info ContactCreate;
newcontactId = ContactCreate.get("id");
PotentialMap = map();
PotentialMap.put("Deal_Name", ifnull(leadDetails.get("Full_Name"),""));
PotentialMap.put("City", ifnull(leadDetails.get("City"),""));
PotentialMap.put("Country", ifnull(leadDetails.get("Country"),""));
PotentialMap.put("State", ifnull(leadDetails.get("State"),""));
PotentialMap.put("Street", ifnull(leadDetails.get("Street"),""));
PotentialMap.put("Zipcode", ifnull(leadDetails.get("Zip_Code"),""));
PotentialMap.put("Description", ifnull(leadDetails.get("Description"),""));
PotentialMap.put("Lead_Source", ifnull(leadDetails.get("Lead_Source"),""));
PotentialMap.put("Account_Name",newaccountId );
PotentialMap.put("Contact_Name",newcontactId );
PotentialCreate = zoho.crm.create("Potentials", PotentialMap);
info PotentialCreate;
newdealId = PotentialCreate.get("id");
// Copy related notes
RelatedNotes = zoho.crm.getRelatedRecords("Notes", "Leads", leadIdLong);
for each note in RelatedNotes
{
notemap = Map();
notemap.put("Parent_Id",newcontactId);
notemap.put("Note_Content",note.get("Note_Content"));
notemap.put("Note_Title",ifnull(note.get("Note_Title"),""));
notemap.put("se_module","Contacts");
notecreate = zoho.crm.create("Notes",notemap);
notemap1 = Map();
notemap1.put("Parent_Id",newaccountId);
notemap1.put("Note_Content",note.get("Note_Content"));
notemap1.put("Note_Title",ifnull(note.get("Note_Title"),""));
notemap1.put("se_module","Accounts");
notecreate1 = zoho.crm.create("Notes",notemap1);
notemap2 = Map();
notemap2.put("Parent_Id",newdealId);
notemap2.put("Note_Content",note.get("Note_Content"));
notemap2.put("Note_Title",ifnull(note.get("Note_Title"),""));
notemap2.put("se_module","Deals");
notecreate2 = zoho.crm.create("Notes",notemap2);
}
// Copy activities
reltasks = zoho.crm.getRelatedRecords("Tasks","Leads",leadIdLong);
for each task in reltasks
{
taskmap = Map();
taskmap.put("What_Id",newaccountId);
taskmap.put("$se_module","Accounts");
taskmap.put("Who_Id",newcontactId);
updatetask = zoho.crm.update("Tasks",task.get("id"),taskmap);
info updatetask;
}
relevents = zoho.crm.getRelatedRecords("Events","Leads",leadIdLong);
for each events in relevents
{
eventmap = Map();
eventmap.put("What_Id",newaccountId);
eventmap.put("$se_module","Accounts");
eventmap.put("Who_Id",newcontactId);
updateevent = zoho.crm.update("Events",events.get("id"),eventmap);
info updateevent;
}
relcalls = zoho.crm.getRelatedRecords("Calls","Leads",leadIdLong);
for each call in relcalls
{
callmap = Map();
callmap.put("What_Id",newaccountId);
callmap.put("$se_module","Accounts");
callmap.put("Who_Id",newcontactId);
updatecall = zoho.crm.update("Calls",call.get("id"),callmap);
info updatecall;
}
// Copy attachment
relatedrcords = zoho.crm.getRelatedRecords("Attachments","Leads",leadIdLong);
attachid = List();
for each ele in relatedrcords
{
attachementId = ele.get("id");
attachid.add(attachementId);
}
for each ele in attachid
{
downloadFile = invokeurl
[
url: "https://www.zohoapis.com/crm/v2/Leads/" + leadId + "/Attachments/" + ele
type: GET
connection : "connectionname"
];
resp = zoho.crm.attachFile("Contacts",newcontactId,downloadFile);
info resp;
resp1 = zoho.crm.attachFile("Accounts",newaccountId,downloadFile);
info resp1;
resp2 = zoho.crm.attachFile("Deals",newdealId,downloadFile);
info resp2;
}
// Copy related list
relateddetails = zoho.crm.getRelatedRecords("Client_Products","Leads",leadIdLong);
for each record in relateddetails
{
updatemap = Map();
updatemap.put("xxxxxx",newcontactId);
updatemap.put("yyyyyyy",newaccountId);
updatemap.put("zzzzzzzzz",newdealId);
customupdate = zoho.crm.updateRecord("customname", record.get("id"), updatemap);
info customupdate;
}
return "";
Notes
- Replace 'connectionname' with the name of the connection.
- Replace 'xxxxxx' with the custom module's Contact LookUp Field API name.
- Replace 'yyyyyyy' with the custom module's Account LookUp Field API name.
- Replace 'zzzzzzzzz' with the custom module's Deal LookUp Field API name.
- Replace 'customname' with the custom module's API name.
- You can remove unnecessary code snippets related to the data you don't want to copy.
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 that needs to be converted and click the new button you added to the top-right area.
- The lead will be converted into an account and contact.
- See whether the lead information—such as custom fields, notes, attachments, activities, and related lists—are transferred to the contact and account.
Note: You must map the custom fields in the Leads module to the fields in the account and contact to transfer their information to it. Learn more
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