Once you qualify a lead, it converts into a contact (and account), for which you can initiate a new deal. Then you can continue pursuing the deal until you win it. During this process, you may accidentally convert one or more unqualified leads into contacts, or maybe you too hastily identified a lead as a potential customer and now wish to undo the action. Presently, it's not possible to undo lead conversion directly using the CRM interface, but you can use our low-code tools to help you turn a contact back into a lead and keep all their important information—like account details, tasks, events, calls, campaigns, products, and attachments—intact.
To convert a contact back into a lead and delete the existing contact record, add a custom button to the contact details page and link it with a custom function, so that next time you can easily undo a lead conversion by clicking just one button.
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 "Getting Started" section below. Learn more
- Test the custom button 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
- Go to Setup > Customization > Modules and Fields > Contacts > Buttons > Create New Button.
- Provide a name for the button. For example: "Convert contact back to lead".
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.
- Copy and paste the code provided below.
- Click Edit Arguments.
- Enter the name as contId and select the value as Contact Id.
- Click Save & Execute.
- Save the changes.
- Select the profiles who can view this custom button.
- Click Save.
The code
continfo = zoho.crm.getRecordById("Contacts", contId.toLong());
mp = map();
mp.put("Last_Name",continfo.get("Last_Name"));
mp.put("Owner",continfo.get("Owner").get("id"));
mp.put("First_Name",ifnull(continfo.get("First_Name"),""));
acctname = ifnull(continfo.get("Company_of_Employment"),"");
if(acctname != "")
{
mp.put("Account_Name",acctname.get("id"));
}
mp.put("Lead_Source",ifnull(continfo.get("Lead_Source"),""));
mp.put("Description",ifnull(continfo.get("Description"),""));
mp.put("Email",ifnull(continfo.get("Email"),""));
mp.put("The_un",ifnull(continfo.get("industry"),""));
mp.put("Lead_Rating_5_Being_the_Strongest",ifnull(continfo.get("Lead_Rating_5_Being_the_Strongest"),""));
mp.put("LinkedIn",ifnull(continfo.get("LinkedIn"),""));
mp.put("Mobile",ifnull(continfo.get("Mobile"),""));
mp.put("Other_Phone",ifnull(continfo.get("Other_Phone"),""));
mp.put("Other_Zip",ifnull(continfo.get("Zip_Code"),""));
mp.put("Other_State",ifnull(continfo.get("State"),""));
mp.put("Other_Street",ifnull(continfo.get("Street"),""));
create = zoho.crm.create("Leads", mp);
info create;
// Notes
RelatedNotes = zoho.crm.getRelatedRecords("Notes", "Contacts", input.contId.toLong());
for each note in RelatedNotes
{
notemap = Map();
notemap.put("Parent_Id",create.get("id"));
notemap.put("Note_Content",note.get("Note_Content"));
notemap.put("Note_Title",note.get("Note_Title"));
notemap.put("se_module","Leads");
notecreate = zoho.crm.create("Notes",notemap);
}
// Tasks
reltasks = zoho.crm.getRelatedRecords("Tasks","Contacts",input.contId.toLong());
for each task in reltasks
{
taskmap = Map();
taskmap.put("What_Id",create.get("id"));
taskmap.put("$se_module","Leads");
taskmap.put("Who_Id","");
updatetask = zoho.crm.update("Tasks",task.get("id"),taskmap);
info updatetask;
}
// Events
relevents = zoho.crm.getRelatedRecords("Events","Contacts",input.contId.toLong());
for each events in relevents
{
eventmap = Map();
eventmap.put("What_Id",create.get("id"));
eventmap.put("$se_module","Leads");
eventmap.put("Who_Id","");
updateevent = zoho.crm.update("Events",events.get("id"),eventmap);
info updateevent;
}
// Calls
relcalls = zoho.crm.getRelatedRecords("Calls","Contacts",input.contId.toLong());
for each call in relcalls
{
callmap = Map();
callmap.put("What_Id",create.get("id"));
callmap.put("$se_module","Leads");
callmap.put("Who_Id","");
updatecall = zoho.crm.update("Calls",call.get("id"),callmap);
info updatecall;
}
// Campaigns
relatedcamp = zoho.crm.getRelatedRecords("Campaigns","Contacts",contId.toLong());
for each camp in relatedcamp
{
mp=map();
mp.put("CAMPAIGNID",camp.get("id"));
resp = zoho.crm.updateRelatedRecord("Campaigns",camp.get("id").toLong(),"Leads",create.get("id"),mp);
info resp;
}
// Products
relatedproducts = zoho.crm.getRelatedRecords("Products","Contacts",contId.toLong());
for each product in relatedproducts
{
mp=map();
mp.put("PRODUCTID",product.get("id"));
resp = zoho.crm.updateRelatedRecord("Products",product.get("id").toLong(),"Leads",create.get("id"),mp);
info resp;
}
//Attachments
relatedrcords = zoho.crm.getRelatedRecords("Attachments","Contacts",contId.toLong());
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/Contacts/" + contId + "/Attachments/" + ele
type: GET
connection : "connectionname"
];
resp = zoho.crm.attachFile("Leads",create.get("id"),downloadFile);
info resp;
}
deleteResp = zoho.crm.invokeConnector("crm.delete",{"module":"Contacts","id":contId});
info deleteResp;
Notes
- Replace "connectionname" with the name of the connection you specified while creating the connection (see the Create a connection section above).
- Make sure to use the accurate API names for their corresponding fields in the code snippet. Learn more
Tips
- To convert a contact back to a lead during a transition, include this code snippet in the Custom Actions section of Blueprints. Learn more
- To convert a contact back into a lead when a field is edited, you can deploy this code snippet as a function in a workflow rule for the Contacts module. Learn more
- Configure and test the function in a sandbox to ensure that further development doesn't disrupt your production environment.
Test the solution
- In the Contacts module, click on a particular contact you want to convert back to a lead.
- Click the custom button you've created in the steps above.
- Check whether a new lead record has been created with the contact details and whether the current contact record has been deleted and moved to the recycle bin.
- Make sure that all important information, including tasks, events, calls, campaigns, products, and attachments, is accessible in the lead record.
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
- ModuleContacts
- 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