Hi
Here is a neat Custom Function that check a created lead to see if a Contact already exists in CRM for the First Name, Last Name and Email.
Before adding the code create a notes single line field and add it to the Leads module. Name the field 'Contact Check'.
When creating the custom function don't forget to click 'Edit Arguments' and add 'leadId' and map it to the 'Lead Id' field.
Here is the Custom Function to add:
leadid_str = leadId.toString();
leadDetails = zoho.crm._getRecordById("Leads",leadId);
form_email = leadDetails.get("Email");
//info form_email;
first_name = leadDetails.get("First Name");
last_name = leadDetails.get("Last Name");
//phone = leadDetails.get("Phone");
contactInfo = zoho.crm._searchRecords("Contacts","(Email|=|" + form_email + ")",1,200);
for each cinfo in contactInfo
{
contactid = cinfo.get("CONTACTID");
}
//info contactid;
if(contactid != null)
{
mp = Map();
mp.put("Latest Notes","Record exists in Contacts");
update = zoho.crm._updateRecord("Leads",leadid_str,mp);
info update;
}
What this custom function does is checks the created lead to see if a duplicate Contact already exists in the Contacts module. If it does, then it will add the note 'Record exists in Contacts' to the 'Contact Check' field you created in your leads module.
After you save this Custom Function you will need to add it to a workflow rule for it to work. Here's how:
1. In CRM go to 'Setup' => 'Automations' => 'Workflow Rules'
2. Create new Workflow Rule for 'Leads'
3. Name the Workflow Rule
3. For ' When ' select 'Create or Edit'
4. ' Condition 1 ' select 'All Records'
5. 'Action' Select 'Function' then attach the custom function you created
Save
I you want to merge the duplicate lead record with the existing contact you can create a second Workflow Rule to achieve this:
1. In CRM go to 'Setup' => 'Automations' => 'Workflow Rules'
2. Create new Workflow Rule for 'Leads'
3. Name the Workflow Rule
3. For ' When ' select 'Field Update' then select the 'Contact Check' field from the dropdown
4. ' Condition 1 ' select 'Records Matching the Conditions' is 'Contact Check' is 'Record exists in Contacts'
5. 'Action' Select 'Convert' and select 'Contact' only (account may already be checked as compulsory).
Save
You are all set!
Please let me know if you found this helpful or if you have any questions. Would love to hear your comments.