Linking Leads With Accounts and Accounts With Multiple Locations

Linking Leads With Accounts In Zoho CRM 

So we can link “Contacts” with “Accounts”, but not “Leads”? This is a basic feature that any company marketing in a business-to-business type industry would require. In this guide, we are going to show you how to create the linkage and integrate it into your workflow. (NOTE: If you already have 2 “Multi-Select Lookup” fields in your “Accounts” module this guide will not work for you)

Step 1 – Separate Active Accounts and Potential Accounts

OK I know this is boring but it’s necessary to keep your CRM clean. 

Lets say you are wanting to keep Accounts separated by certain statuses, something like “active accounts” for the ones that are currently engaged in business with your company, and “potential accounts” for the ones you are pursuing. Setting these as individual layouts will not only help you from a report view, but will also allow you to control what certain user groups can access.

In this walkthrough, we’re going to create 3 layouts in Zoho CRM for “Account”

Standard – is going to be for active accounts and will not show accounts unless they are paying clients 

Potentials – are for accounts that are being actively pursued, and will be the layout where we can see the lead contacts that are related. 

Locations – this will show the individual locations of our accounts so that we can add our related leads to the accounts while also notating their locations  

To create these layouts you will need to: Go to settings 

Zoho Settings Icon

 

 

 

Modules and Fields

 

Modules and fields

Select the “Accounts” module. (Now, here you need to decide if you want the lead information to show on all of the other layouts, or if you want it to only show on the “Potentials” layout made specifically for leads. In this example we do NOT want the “Leads” fields to show anywhere but the “Potentials” module)

Select the “New Layout” option and choose the layout you would like to clone

Select New Layout - Zoho CRM

Step 2 - Create A Multi-Select Lookup

In the left hand menu drag the “Multi-Select Lookup” into your desired area and fill out the options like this: 

(the labels in this image directly reflect the labels within the deluge code within this article. You can choose whatever options you would like, just know you will need to make several modifications to the code. Our suggestions would be to use the options below and change them at a later time, this way the API names will stay the same and the functions will continue to work) 

Multi Select Module For Leads And Accounts Zoho CRM

After this you will notice a related list showing up in your “Leads” and “Accounts” module, as well as a new “Linking Module” created. In our use case we don’t really want other users to see the linking module, so we will restrict its view to “Administrators” only (We refer to this as “Ghost Modules”)

Related Leads Accounts Leads - Zoho CRM
Related List In Accounts

And if you want to rename the list, scroll through the data of a lead until you find the list, select the pencil icon and choose the name you would like to use.

Step 3 - Customize The Related Lists In Both Modules

rename related lists - Zoho CRM

Now we need to decide how we want to automate, parse and store the data. In our scenario when a “Lead” record is created we need to gather information for that lead, as well as the information needed for the “Account”. To do this we create a few custom fields within the “Leads” module that are strictly for the creation of the Account record. 

Lead And Accounts Link Map - Zoho CRM

Step 4 - Create A Custom Function

Here is the deluge code for Zoho CRM to connect “Leads” with “Accounts”

 If you have not created a custom function before you can look at this reference guide on how to set them up

Make sure to set the argument for the variable “leadid”

				
					====Zoho Deluge Custom Function | Link Leads With Accounts====

//Define Variables From Lead
data = zoho.crm.getRecordById("Leads",leadid); //make sure to set argument for leadid
email = data.getJSON("Email");
name = data.getJSON("Company");
address = data.getJSON("Business_Street");
address2 = data.getJSON("Business_Street_2");
zipcode = data.getJSON("Business_Zip");
city = data.getJSON("Business_City");
state = data.getJSON("Business_State");
//Search Accounts Using Lead Variables As Search Criteria
search = zoho.crm.searchRecords("Accounts","(Account_Name:equals:" + name + ")");
//debug info search;
{
	//Assign Account To Layout
	layoutmap = Map();
	layoutmap.put("name","Potentials");
	layoutmap.put("id","4993605000000382563");
	//Map The Data For The New Account
	practicemap = Map();
	practicemap.put("Account_Name",name);
	practicemap.put("Billing_Street",address + " " + address2);
	practicemap.put("Billing_Code",zipcode);
	practicemap.put("Billing_City",city);
	practicemap.put("Billing_State",state);
	practicemap.put("Type","PCP");
	practicemap.put("Layout",layoutmap);
	practicemap.put("Status","Lead");
	//Creates The New Account
	practice = zoho.crm.createRecord("Accounts",practicemap);
	accountid = practice.getJSON("id");
	//Map The Related Lead Information
	relatedmap = Map();
	relatedmap.put("Related_Leads",leadid);
	relatedmap.put("Related_Accounts",accountid);
	relatedmap.put("Email",email);
	//Create The Related Lead
	related = zoho.crm.createRecord("Account_Leads",relatedmap);
	//debug info practice;

				
			

The above function works for creating the related “Account” and associating the lead with that account, but  if you are working with several “Leads” that belong to one “Account” the above code will not help you prevent duplicates. In order to avoid any duplicate “Accounts” you would need to make sure the custom function checks for any “Accounts” that match the “Company” name within the “Leads” module. 

Untitled Diagram.drawio

Here is the deluge code for Linking Leads With Accounts, and Preventing Duplicates

				
					====Zoho Deluge Custom Function | Leads | Set Argument For leadid====

//Define Variables From Lead
data = zoho.crm.getRecordById("Leads",leadid);
email = data.getJSON("Email");
name = data.getJSON("Company");
address = data.getJSON("Business_Street");
address2 = data.getJSON("Business_Street_2");
zipcode = data.getJSON("Business_Zip");
city = data.getJSON("Business_City");
state = data.getJSON("Business_State");
//Search Accounts Using Lead Variables As Search Criteria
search = zoho.crm.searchRecords("Accounts","(Account_Name:equals:" + name + ")");
info search;

//Conditional Statement "If The Search Is Empty And No Account Exists, Create New Account
 And Add The Lead As A Related Lead"

if(search.isEmpty())
{
	//Assign Account To Layout
	layoutmap = Map();
	layoutmap.put("name","Potentials");
	layoutmap.put("id","4993605000000382563");
	//Map The Data For The New Account
	practicemap = Map();
	practicemap.put("Account_Name",name);
	practicemap.put("Billing_Street",address + " " + address2);
	practicemap.put("Billing_Code",zipcode);
	practicemap.put("Billing_City",city);
	practicemap.put("Billing_State",state);
	practicemap.put("Type","PCP");
	practicemap.put("Layout",layoutmap);
	practicemap.put("Status","Lead");
	//Creates The New Account
	practice = zoho.crm.createRecord("Accounts",practicemap);
	accountid = practice.getJSON("id");
	//Map The Related Lead Information
	relatedmap = Map();
	relatedmap.put("Related_Leads",leadid);
	relatedmap.put("Related_Accounts",accountid);
	relatedmap.put("Email",email);
	//Create The Related Lead
	related = zoho.crm.createRecord("Account_Leads",relatedmap);
	info practice;
}
else
{
            //Map The Related Lead Information
	accountid = practice.getJSON("id");
	//Map The Related Lead Information
	relatedmap = Map();
	relatedmap.put("Related_Leads",leadid);
	relatedmap.put("Related_Accounts",accountid);
	relatedmap.put("Email",email);
	//Create The Related Lead
	related = zoho.crm.createRecord("Account_Leads",relatedmap);
	info practice;
}





				
			

In this function, when a  “Lead” is created we use the “Company” field to search for “Accounts” with matching names. If an account Exists we just add the “Related Lead” to that “Account”, if an “Account” doesn’t already exist we create a new “Account” and add the “Related Lead” to the new account. 

But wait there’s more….

What if we have different locations or branches for each account? 

This is something that is pretty common, and in a lot of cases the location of an “Account” can drastically effect the way in which we pursue a “Lead”. Zoho has a “Parent/Child” relationship setup for “Accounts”, but it has some limitations we would consider deal breakers, such as:

  1. No customizations can be made to the naming convention (which is a huge problem for those who have renamed the “Accounts” module). 
  2. Unable to see all “Child” accounts when viewing them individually (only the parent accounts).
  3. Relating “Contacts” or “Leads” to the “Child Accounts” is a mess. 

If these are also deal breakers for you, you may want to delete the current “parent/child” relationship and create your own. Click here to see how to setup Multi-Location Accounts and “Account Related Leads” 

 

but wait theres more edited

Step 5 - Create A Workflow To Execute The Function

Now that the modules have been created and configured, the next step is to build out the workflow that will execute the custom function in Zoho CRM. 

To do this:

  1. Go to Settings >>> Workflow Rules >>> Create Rule 
  2. Select “Leads” for the module, and name the rule whatever you like 
leads related accounts workflow rule - Zoho CRM

3. For the “When”, select “On a record action” and tick the box for “Create”

On a record action Leads and accounts workflow - Zoho CRM

4. The condition is a preference, for our rule we only want our function to run if the “Lead” created has a company listed. 

New Rule Company is not blank

5. From the “Action Options” select “Functions” and choose the function from above

Select Functions
Functions Select

Now when you create the lead, the process should work. Make sure to test it a few times and be sure to let us know if there are any errors. 

 

If you are doing a large import, we’ve noticed that Zoho CRM will take up to an hour to execute the function. 

Multi-Location Accounts For Account-Related Leads In Zoho CRM

Before setting up the new :Multi-Location Accounts: configuration you should remove the current parent/child relationship from Zoho CRM. This will keep things cleaner, and make understanding the data a lot easier.

 

Head to Setup >>> Modules and Fields >>> Accounts and start with “Standard” find “Parent Account” and select “Remove Field”

delete parent account - Zoho CRM

Now select “Detailed View” at the top, and look for the related list labeled “Member Accounts”  

Remove Related List Member Accounts

Now that those are out of the way we can create a “Locations” Multi-Select Lookup and label the fields like this: 

 

(the labels in this image directly reflect the labels within the deluge code within this article. You can choose whatever options you would like, just know you will need to make several modifications to the code. Our suggestions would be to use the options below and change them at a later time, this way the API names will stay the same and the functions will continue to work) 

related locations

Now that the “Account Locations” relationship has been created we can incorporate it into our “Related Leads” / “Related Accounts”

So now our flow will look like this:

Untitled Diagram.drawio 1

Here is the deluge code for Linking Leads and Accounts, and Multiple Locations

				
					====Zoho Deluge Custom Function | Link Leads With Accounts, Check For Duplicates, Add Locations====

//Define Variables From Lead
data = zoho.crm.getRecordById("Leads",leadid);
email = data.getJSON("Email");
name = data.getJSON("Company");
address = data.getJSON("Business_Street");
address2 = data.getJSON("Business_Street_2");
zipcode = data.getJSON("Business_Zip");
city = data.getJSON("Business_City");
state = data.getJSON("Business_State");
//Search Accounts Using Lead Variables As Search Criteria
search = zoho.crm.searchRecords("Accounts","(Account_Name:equals:" + name + ")");
info search;
//Conditional Statement "If The Search Is Empty And No Account Exists, Create New Account And Add The Lead As A Related Lead"
if(search.isEmpty())
{
	//Assign Account To Layout
	layoutmap = Map();
	layoutmap.put("name","Potentials");
	layoutmap.put("id","4993605000000382563");
	//Map The Data For The New Account
	practicemap = Map();
	practicemap.put("Account_Name",name);
	practicemap.put("Billing_Street",address + " " + address2);
	practicemap.put("Billing_Code",zipcode);
	practicemap.put("Billing_City",city);
	practicemap.put("Billing_State",state);
	practicemap.put("Type","PCP");
	practicemap.put("Layout",layoutmap);
	practicemap.put("Status","Lead");
	//Creates The New Account
	practice = zoho.crm.createRecord("Accounts",practicemap);
	accountid = practice.getJSON("id");
	//Map The Related Lead Information
	relatedmap = Map();
	relatedmap.put("Related_Leads",leadid);
	relatedmap.put("Related_Accounts",accountid);
	relatedmap.put("Email",email);
	//Create The Related Lead
	related = zoho.crm.createRecord("Account_Leads",relatedmap);
	info practice;
}
else
{
	//If The Search Is Not Empty And An Account Name Matches, Search The Address To See If This Is Another Location
	street = search.getJSON("Billing_Street");
	address_search = zoho.crm.searchRecords("Accounts","(Billing_Street:starts_with:" + street + ")");
	info address_search;
}
//Conditional Statenent "If The Search Is Empty And The Address Does Not Match An Existing Account, Create A New Location "
if(address_search.isEmpty())
{
	layoutmap = Map();
	layoutmap.put("name","Locations");
	layoutmap.put("id","4993605000000382737");
	mainlocationmap = Map();
	mainlocationmap.put("name",address_search.getJSON("Account_Name"));
	mainlocationmap.put("id",address_search.getJSON("id"));
	practicemap = Map();
	practicemap.put("Account_Name",name);
	practicemap.put("Billing_Street",address + " " + address2);
	practicemap.put("Billing_Code",zipcode);
	practicemap.put("Billing_City",city);
	practicemap.put("Billing_State",state);
	practicemap.put("Layout",layoutmap);
	practicemap.put("Status","Lead");
	practicemap.put("Main_Location",address_search.getJSON("id"));
	practice = zoho.crm.createRecord("Accounts",practicemap);
	accountid = practice.getJSON("id");
	locationmap = Map();
	locationmap.put("Main_Location",address_search.getJSON("id"));
	locationmap.put("Locations1",accountid);
	addlocation = zoho.crm.createRecord("Account_Locations",locationmap);
	relatedmap = Map();
	relatedmap.put("Related_Leads",leadid);
	relatedmap.put("Related_Accounts",accountid);
	relatedmap.put("Email",email);
	related = zoho.crm.createRecord("Account_Leads",relatedmap);
	//OLD
	accountid = address_search.getJSON("id");
	relatedmap = Map();
	relatedmap.put("Related_Leads",leadid);
	relatedmap.put("Related_Accounts",accountid);
	relatedmap.put("Email",email);
	related = zoho.crm.createRecord("Account_Leads",relatedmap);
}
//If The Address Does Match An Existing Accountt, Just Create The Related Lead Record
else
{
	accountid = address_search.getJSON("id");
	relatedmap = Map();
	relatedmap.put("Related_Leads",leadid);
	relatedmap.put("Related_Accounts",accountid);
	relatedmap.put("Email",email);
	related = zoho.crm.createRecord("Account_Leads",relatedmap);
}


				
			

Table of Contents