Create Accounts from Leads with all the data at the click of a button
Business scenario:
Opportunities come in strange ways. One day there might be no good leads, but the next day you might bag a million dollar deal. Or there might be a lot of deals with smaller figures from different leads. Either way, there's a lotta work for you. And by that, I mean gathering lead details, following up with them, documenting your interactions with them and so on. If there are multiple leads, you can imagine what you're gonna go through.
At times, leads would just become contacts and there are also times where leads would be from other companies. Zoho CRM offers you the provisions to automatically create a contact from a lead, but not an account. Wouldn't it save a lot of your work and time if an Account (company) record is created with all the details, interactions and information from a lead record?
Although it is conventional process to get a lead, create a contact and then add an account for the said lead, there might arise a situation where contacts are a section that are not required. This week's function is for those scenarios.
It works in the same way as Lead to Contact conversion, but just that it's Lead to Account.
Getting started with the function:
- Go to Setup > Customization > Modules and Fields > Select the required module > Links and Buttons > + New Button.
- Provide a name for the button. Add a description(optional).
- Choose View Page from the drop-down list.
- Select Writing Function from the subsequent drop-down.
- Provide a name for the custom function. Add a description(optional).
- Copy the code given below.
- Click Edit Arguments.
- Enter the name as leadId and select the value as Lead Id.
- Save the changes.
- Select the profiles who can see this button.
- Click Save.
The Code:
leadDetails = zoho.crm.getRecordById("Leads", leadId.toLong());
accountmap = map();
accountmap.put(("Account_Name"), ifnull(leadDetails.get("Full_Name"),""));
accountmap.put("App_Out", ifnull(leadDetails.get("App Out"),""));
accountmap.put("Approved_Date", ifnull(leadDetails.get("Approved_Date"),""));
accountmap.put("Associated_MIDs", ifnull(leadDetails.get("Associated_MIDs"),""));
accountmap.put("Transaction_Fee", ifnull(leadDetails.get("Transaction_Fee"),""));
accountmap.put("Type_of_Ownership", ifnull(leadDetails.get("Type_of_Ownership"),""));
accountmap.put("Website", ifnull(leadDetails.get("Website"),""));
accountmap.put("Billing_Code", ifnull(leadDetails.get("Zip_Code"),""));
accountmap.put("Yelp", ifnull(leadDetails.get("Yelp"),""));
accountcreate = zoho.crm.create(("Accounts"), accountmap);
newacctId = (accountcreate).get("id");
RelNotes = zoho.crm.getRelatedRecords("Notes", "Leads", leadId.toLong());
for each ele in RelNotes
{
notemap = Map();
notemap.put("Parent_Id",newacctId);
notemap.put("Note_Content",note.get("Note_Content"));
notemap.put("se_module","Accounts");
notecreate = zoho.crm.create("Notes",notemap);
info notecreate;
}
TaskDetails = zoho.crm.getRelatedRecords("Tasks", "Leads", leadId.toLong());
for each ele1 in TaskDetails
{
taskMap = map();
taskMap.put("What_Id", newacctId);
taskMap.put("se_module","Accounts");
UpdateTask = zoho.crm.update("Tasks", ele1.get("id"), taskMap);
}
EventDetails = zoho.crm.getRelatedRecords("Events", "Leads", leadId.toLong());
for each ele2 in EventDetails
{
eventMap = map();
eventMap.put("What_Id", newacctId);
eventMap.put("se_module","Accounts");
UpdateEvent = zoho.crm.update("Events", ele2.get("id"), eventMap);
}
CallDetails = zoho.crm.getRelatedRecords("Calls", "Leads", leadId.toLong());
for each ele3 in CallDetails
{
callMap = map();
callMap.put("What_Id", newacctId);
callMap.put("se_module","Accounts");
UpdateCall = zoho.crm.update("Calls", ele3.get("id"), callMap);
}
return "Success";
Note:
- You can further customize by creating a custom field in leads module named "Account" or "Company". You can map this custom field to the Account name to create an account with the organization's name.
- 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!