Blog

How to eliminate duplicates in Zoho CRM when working with Facebook Leads? Learn how to control entries by any field

When a business receives leads from Facebook, it’s common for the same person to leave contacts multiple times: in different campaigns, from different forms, or from different devices. In Zoho CRM, this is the reason for duplicate leads.

What problems create duplicates:

  • managers waste time on re-processing,
  • marketing analytics are distorted,
  • the customer base is “clogged up”.

Limitations of the standard duplicate check in Zoho CRM

  • The check only works on a limited set of fields (usually email).
  • You can't set up cascading rules (for example, "phone first, then email").
  • When converting Facebook leads to existing contacts, advertising campaign data and UTM tags are often lost.

Solution: Custom duplicate control for Facebook requests in Zoho CRM

We have developed a script on Deluge that:

  • checks leads by any fields (phone, email, custom),
  • saves Facebook advertising data and UTM tags,
  • converts a lead into either a new or an existing contact without creating a duplicate,

always creates a deal so that no application is lost.
info LeadID;
// Get Lead
lead = zoho.crm.getRecordById("Leads",LeadID);
info lead;
Phone = lead.get("Phone");
info Phone;
Email = lead.get("Email");
info Email;
Name = lead.get("Full_Name");
info Name;
City = lead.get("City");
info City;
Ad_Account = lead.get("Ad_Account");
Ad_Account_ID = lead.get("Ad_Account_ID");
Ad_Campaign = lead.get("Ad_Campaign");
Ad_Campaign_ID = lead.get("Ad_Campaign_ID");
Ad_ID = lead.get("Ad_ID");
Ad_Set = lead.get("Ad_Set");
Ad_Set_ID = lead.get("Ad_Set_ID");
Ads = lead.get("Ads");
Facebook_Page = lead.get("Facebook_Page");
Facebook_Page_ID = lead.get("Facebook_Page_ID");
form_name = lead.get("form_name");
Lead_Source = lead.get("Lead_Source");
utm_campaign = lead.get("utm_campaign");
utm_content = lead.get("utm_content");
utm_medium = lead.get("utm_medium");
utm_source = lead.get("utm_source");
utm_term = lead.get("utm_term");
Language = lead.get("Language");
Description = lead.get("Description");
// check contact
Param = "(Phone:equals:" + Phone + ")";
Contact = zoho.crm.searchRecords("Contacts",Param);
info Contact;
ValueRep = Contact.isEmpty();
info ValueRep;
if(ValueRep == true)
{
	Param = "(Email:equals:" + Email + ")";
	Contact = zoho.crm.searchRecords("Contacts",Param);
	info Contact;
	Value = Contact.isEmpty();
	info ValueRep;
}
if(Contact.isEmpty() = true)
{
	deal_values = Map();
	deal_values.put("Deal_Name",Name);
	deal_values.put("Stage","Qualification");
	ConvertLead = zoho.crm.convertLead(LeadID,{"Deals":deal_values});
	info ConvertLead;
}
else
{
	Contact = Contact.toString();
	ContactID = Contact.get("id");
	info ContactID;
	values_map = Map();
	values_map.put("overwrite",true);
	values_map.put("Contacts",ContactID);
	response = zoho.crm.convertLead(LeadID,values_map);
	info response;
	//  Create Deal
	values_map.put("Deal_Name",Name);
	values_map.put("Stage","Qualification");
	values_map.put("Amount","0");
	values_map.put("Contact_Name",ContactID);
	values_map.put("Ad_Account",Ad_Account);
	values_map.put("Ad_Account_ID",Ad_Account_ID);
	values_map.put("Ad_Campaign",Ad_Campaign);
	values_map.put("Ad_Campaign_ID",Ad_Campaign_ID);
	values_map.put("Ad_ID",Ad_ID);
	values_map.put("Ad_Set",Ad_Set);
	values_map.put("Ad_Set_ID",Ad_Set_ID);
	values_map.put("Ads",Ads);
	values_map.put("Facebook_Page",Facebook_Page);
	values_map.put("Facebook_Page_ID",Facebook_Page_ID);
	values_map.put("form_name",form_name);
	values_map.put("Lead_Source",Lead_Source);
	values_map.put("utm_campaign",utm_campaign);
	values_map.put("utm_content",utm_content);
	values_map.put("utm_medium",utm_medium);
	values_map.put("utm_source",utm_source);
	values_map.put("utm_term",utm_term);
	values_map.put("Type","Existing Business");
	values_map.put("Language",Language);
	values_map.put("Phone",Phone);
	values_map.put("Description",Description);
	values_map.put("City",City);
	response = zoho.crm.createRecord("Deals",values_map,{"trigger":{"workflow"}});
	info response;
}

How custom script works in Zoho CRM

Step 1. Getting a lead

Contact information (Phone, Email, Full_Name, City) and advertising tags (Ad_Account, Ad_Campaign, Ad_Set, Ad_ID, Facebook_Page, form_name, utm_*, Language) are downloaded from the Facebook application to Zoho CRM.

Step 2. Checking for duplicates

  • First, search by phone.
  • If the contact is not found, search by email.
  • You can extend the check to custom fields (for example, TIN, passport, client ID).

Step 3. Two scenarios

  1. Contact not found → lead is converted into a new contact, and a deal with the Qualification stage is immediately created.
  2. Contact found → lead is converted in favor of an existing contact, and a deal is created for it, where all advertising and UTM data are transferred.

Step 4. Saving analytics

Even a repeated application is recorded as a new deal, where the following are reflected:
  • advertising campaign,
  • advertisement,
  • traffic source (utm_source, utm_medium, utm_campaign).

Benefits of working with Facebook Leads

  • No duplicates — the database is clean, contacts are not duplicated.
  • Marketing analytics is saved — you can see which campaign led to the deal.
  • Deals are always created — managers work with each application, marketing receives data for reporting.

Case: example of the solution in action

1) The client leaves a request in the Facebook form.
2) The script checks: is there already a contact with such a phone number or email?
  • If not, a new contact and a deal are created.
  • If there are, the lead is converted into an existing contact, and a deal with advertising data is created.
3) The CRM always has a clean database, and the analytics reflect the real effectiveness of advertising.

Pitfalls in implementation

  • Empty values: make sure the phone or email are not empty, otherwise the search filter may be incorrect.
  • Search results: searchRecords returns a list, so the ID should be retrieved as Contact.get(0).get("id").
  • Condition syntax: use ==, not =.
  • Description transfer: if you need a description from the lead, it should be taken explicitly.
  • Flexible check: it is better to put the list of fields for searching for duplicates in an array and iterate.

Implementation results

  • We remove duplicates when processing Facebook applications.
  • We save full advertising data in transactions.
  • We increase the transparency of analytics and the efficiency of managers.

Conclusion

If you use Facebook Leads and want to:

  • exclude duplicates in Zoho CRM,
  • save all advertising data and UTM tags,
  • see end-to-end analytics,

then the standard functionality of Zoho CRM will not be enough. The optimal solution is a custom script on Deluge.

At Business Lab we implement Zoho CRM for real business tasks: from duplicate control to integration with advertising platforms and building end-to-end analytics.